ТРМ 138 и C#. Вывести данные из трм в c#
Как вывести данные из трм при помощи c# и библиотеки System.IO.Ports (serialports).
Мой код:
using System;
using System.IO.Ports;
namespace Корначенко_Д
{
class Program
{
private string stroka="";
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
this.Invoke(new EventHandler(DoUpdate));
serialPort1.PortName = "COM1"; //Указываем порт.
serialPort1.BaudRate = 9600; // скорость.
serialPort1.DataBits = 8;
serialPort1.Open(); //Открываем порт.
}
private void DoUpdate(object s,EventArgs e)
{
stroka = stroka + serialPort1.ReadExisting();
serialPort1.Close(); //Закрываем порт.
}
public static void Main(string[] args)
{
unsigned crc;
byte[] command;
int a = 3<<1;
crc = Hash((command[3] << 1), 7,
Hash(command[2] << 1, 7,
Hash(command[1] << 1, 7,
Hash(command[0] << 1, 7, 0))));
}
public unsigned Hash(char Byte, char nbit, unsigned CRC)
{
for (int i = 0; i < nbit; i++, Byte <<= 1)
{
if ( ( Byte ^ (CRC>>8) ) & 0x80 )
{
CRC <<= 1; CRC ^= 0x8F57;
}
else CRC <<= 1;
}
return CRC;
}
}
}