开发者

Pinnacle Plus+ power supply RS232 communication in C#

I am trying to communicate to Pinnacle Plus+ power supply via RS232 link but get no reply from the unit. Unit is configured to address 1 and baud rate 9600.

The code is in C#

Here is what I have done:

SerialPort PinnacleSerial开发者_如何学运维Port = new SerialPort("COM3", 9600, Parity.Odd, 8, StopBits.One);

PinnacleSerialPort.ReadTimeout = 3000;
PinnacleSerialPort.Open();

byte[] b = { 8, 128, 136 };
PinnacleSerialPort.Write(b, 0, b.Length);
Thread.Sleep(1000);

try
{
    int bytes = PinnacleSerialPort.BytesToRead;//RETURNS 0 (ZERO)
    Console.WriteLine(string.Format("Bytes to read: {0}", bytes));

    byte[] comBuffer = new byte[bytes];
    PinnacleSerialPort.Read(comBuffer, 0, bytes);
}
catch (Exception ex)
{
    Console.WriteLine(ex.Message);
}

Console.ReadKey();

According to documentation packet consist of: header, command, data bytes(if present), checksum.

Header(1byte): first 3 bits is the number of data bytes. In my case it is 0 = 000 the last 5 bits is the unit number packet is addressed to. In my case it is 1 = 00001 Full header would be 00001 000 or decimal 8 Data bytes: these are omitted as they are not needed with this command Command(1byte): is command number. In my case it is 10000000 = 128 Checksum(1byte): is XOR of in my case header and command bytes which is 10001000 = 136

Based on this info i constructed and sent the following byte[] array:

byte[] b = {8, 128, 136}

Reply should be 4 ASCII character: "PLUS";

However I get no reply at all.

I tried different other commands, but get no reply either.

If anyone has experience with this unit, please advice on what am I doing wrong.

Really appreciate.

Alex


You might need to configure flow control. Never understood why serial port parameters specify baud and parity but not flow control, since if anything it's more important than the others.


The problem wasn't the code. The code is good. It was faulty connection - RS232 cable. Since it's been replaced everything works great. Thanks everyone for your help.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜