V1Connect Forum
February 08, 2010, 05:48:57 pm *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: C# Code Sample to Read V1Connect's Data  (Read 277 times)
V1Connect
Administrator
Newbie
*****
Posts: 11


View Profile WWW
« on: August 16, 2009, 09:52:53 pm »

This should be all the code necessary to connect to the V1CS and read its data. Do with the data what you like (display, log, etc).

Code:
SerialPort serialPort = new SerialPort();

serialPort.BaudRate = 9600;
serialPort.DataBits = 8;
serialPort.Parity = 0;
serialPort.StopBits = StopBits.One;
serialPort.Handshake = Handshake.None;

serialPort.PortName = "COM1";
serialPort.Open();

try
{
    serialPort.Write("p"); //Power on the V1Connect
    while (serialPort.IsOpen)
    {
        char[] data = serialPort.ReadTo(" ").ToCharArray();
        if (data.Length == 17) //Ensure we read all the bytes
        {
            int strength = Int32.Parse("" + data[1]);

            bool xOn = (data[2] == '1');
            bool kOn = (data[3] == '1');
            bool kaOn = (data[4] == '1');
            bool laserOn = (data[5] == '1');

            bool A = (data[6] == '1');
            bool B = (data[7] == '1');
            bool C = (data[8] == '1');
            bool D = (data[9] == '1');
            bool E = (data[10] == '1');
            bool F = (data[11] == '1');
            bool G = (data[12] == '1');
            bool dp = (data[13] == '1');
           
            bool frontArrow = (data[14] == '1');
            bool sideArrow = (data[15] == '1');
            bool rearArrow = (data[16] == '1');
           
            //Display the values
        }
    }
}
catch (Exception e)
{

}
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!