Page 1 of 1

Problem with sending chars through the serial port

Posted: Thu Aug 29, 2013 9:55 am
by fsturlese
Hello, I have modified the sample program by Ron to send characters out of the COM port, but some of the chars get altered. It seems that the characters having the MSB set to 1 are converted to 3F regardless of their value.

The code I wrote is reported below, the commented lines show the actual value sent out by the serial port, caught with a serial sniffer. I am using iX 2.0 SP1 2.01.463.0, PC target.

Am I doing the wrong way to initialize the strings?

Thanks,
Federico
=====================
namespace Neo.ApplicationFramework.Generated
{
using System.Windows.Forms;
using System;
using System.Drawing;
using Neo.ApplicationFramework.Tools;
using Neo.ApplicationFramework.Common.Graphics.Logic;
using Neo.ApplicationFramework.Controls;
using Neo.ApplicationFramework.Interfaces;


public partial class Screen1
{
void SendMaxAddressed_Click(System.Object sender, System.EventArgs e)
{
Globals.SerialComScript.Send("\x07\x01\x42\x52\x54\x01\x0E\xFF\x00");
//OUTPUT ON THE COM PORT: 07 01 42 52 54 01 0E 3F 00
}

void SendMaxBroad_Click(System.Object sender, System.EventArgs e)
{
Globals.SerialComScript.Send("\x07\xFF\x42\x52\x54\x01\x10\xFF\x00");
//OUTPUT ON THE COM PORT: 07 3F 42 52 54 01 10 3F 00
}

void SendMidAddressed_Click(System.Object sender, System.EventArgs e)
{
Globals.SerialComScript.Send("\x07\x01\x42\x52\x54\x01\x0E\x7F\x80");
//OUTPUT ON THE COM PORT: 07 01 42 52 54 01 0E 7F 3F
}

void SendMidBroad_Click(System.Object sender, System.EventArgs e)
{
Globals.SerialComScript.Send("\x07\xFF\x42\x52\x54\x01\x10\x7F\x80");
//OUTPUT ON THE COM PORT: 07 3F 42 52 54 01 10 7F 3F
}

void SendMinAddressed_Click(System.Object sender, System.EventArgs e)
{
Globals.SerialComScript.Send("\x07\x01\x42\x52\x54\x01\x0E\x00\xFF");
//OUTPUT ON THE COM PORT: 07 01 42 52 54 01 0E 00 3F
}

void SendMinBroad_Click(System.Object sender, System.EventArgs e)
{
Globals.SerialComScript.Send("\x07\xFF\x42\x52\x54\x01\x10\x00\xFF");
//OUTPUT ON THE COM PORT: 07 3F 42 52 54 01 10 00 3F
}
}
}

Re: Problem with sending chars through the serial port

Posted: Fri Aug 30, 2013 9:26 am
by fsturlese
Problem found. It was due to the Unicode string encoding. I have changed the code to use the SerialPort.Write (Byte[], Int32, Int32) overload and now it works fine.
Regards,
Federico.