I am using the ZStar3 with the development API Zstartlib.dll. I develop a program in Visual C# 2008 Expression Edition, but it does not work correctelly. I search other references in the internetcode but don't exits. There are some diferences between the demo project and the following ?
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms;
using Freescale.ZStarLib;
namespace WindowsFormsApplication1 { public partial class Form1 : Form { private ZStar3 theZStar = new ZStar3(); private ZStarSensor theSensor = null;
public Form1() { theSensor = theZStar.GetSensor(0);
InitializeComponent();
// Event when new burst data was received theZStar.OnBurstDataReceived += new ZStar3.OnBurstDataReceivedHandler(theZStar_OnBurstDataReceived); // Event that occur when list of Active sensor was changed theZStar.OnActiveSensorsChanged += new ZStar3.OnActiveSensorsChangedHandler(theZStar_OnActiveSensorsChanged); // Event that occur if ZStarLib lost Connection on Comport theZStar.OnConnectionLost += new ZStar3.OnConnectionLostHandler(theZStar_OnConnectionLost); }
// List Of Active sensor was changed void theZStar_OnActiveSensorsChanged(object sender, byte sensor) { // Is first sensor present??? if ((theZStar.ActiveSensorsMask & 0x0001) == 0x0001) { // Enable Burst Data Receive for this sensor theSensor.BurstDataReceiveEnable = true; // Enable global Burst mode theZStar.BurstModeEnabled = true; // Switch status label to Connected label1.Text = "Conectado"; } else // Sensor index 0 is not connected { // Disable Burst Data Receive for this sensor theSensor.BurstDataReceiveEnable = false; // Disable global Burst mode theZStar.BurstModeEnabled = false; // Switch status label to DisConnected label1.Text = "Desconectado"; } }
// ZStarLib lost connection with ZStar hardware void theZStar_OnConnectionLost(object sender) { // Perform Close port button button2.PerformClick(); // Show Error Message MessageBox.Show("Conexão serial perdida!", "Conexão ZStarLib", MessageBoxButtons.OK, MessageBoxIcon.Error); }
// New Burst data was received void theZStar_OnBurstDataReceived(object sender, byte sensor) { // Are these data from our sensor 0 if (sensor == 0) while (theSensor.GetBurstData()) // Get all pending data in Burst Data FIFO Buffer { // Update labels with values of actual acceleration for all axes richTextBox1.AppendText( String.Format("{0:F2}g", theSensor.RealX) ); richTextBox1.AppendText(String.Format("{0:F2}g", theSensor.RealY)); richTextBox1.AppendText(String.Format("{0:F2}g", theSensor.RealZ)); } }
// Check ZStarLib ComPort status and selected item in List box if (!theZStar.IsPortOpen && comboBox1.SelectedItem != null) { // If ComPort exist and ZStarLib has closed port // Try to open selected port if (!theZStar.OpenPort(((ComPortInfo)comboBox1.SelectedItem).PortNum)) { // If Failed, show Error message MessageBox.Show("Comunicação serial não iniciada", "Conexão ZStarLib", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); // And go out return; }
// Check USB_Stick type (has to be known!!) if (theZStar.ZStarUsbStickType == ZStar3.UsbStickType.Unknown) { // Unknown USB Stick type // Close opened port theZStar.ClosePort(); // And show Error Message MessageBox.Show("Este não é um dispositivo ZStar3!!!"); return; }
// Disable / Enable all depends objects
// SetUp Enable of all controls on form comboBox1.Enabled = false; button3.Enabled = false; button1.Enabled = false; button2.Enabled = true;
// Disable for all sensor burst data theZStar.BurstDataReceiveEnableMask = 0x0000;
// Keep new sensors(without power switch) sensor awake up when ZStarLib runs theZStar.SleepDisabled = true; } }
Without knowing the methods or properites in starlib.dll it's nearly impossible to trace through this code. However, one thing to try first is to makeInitializeComponent() the first statement in Form1's constructor.