开发者

Problem while using Extended ASCII Values

I am doing a project w开发者_高级运维ith a PLC, im using sockets to interact with server listening on the PLC.I gave the instructions in the ASCII Format,untill 127 my instructions are working fine,when it exceeds 127 ,the code works but proper values are not sent to the PLC . how to overcome this.

s= 130;

Query = Convert.ToChar(00).ToString() + Convert.ToChar(00).ToString() + Convert.ToChar(00).ToString() + Convert.ToChar(00).ToString() + Convert.ToChar(00).ToString() + Convert.ToChar(06).ToString() + Convert.ToChar(01).ToString(); // Headder Query = Query + Convert.ToChar(06).ToString() + Convert.ToChar(AddrUB).ToString() + Convert.ToChar(AddrLB).ToString() + Convert.ToChar(valueUB).ToString() + Convert.ToChar(s).ToString() ;

after converting it to char s becomes a special symbol,instead of writing 130 in the plc the query write it as 63, whats happening in the conversion,please help me to solve this


ASCII 63 is question mark. The main reason of some character above 127 to turn into question mark is conversion from one code page to another that does not support the character in question. So basically there is some conversion happening.

The solution is not to work with strings. PLC understands bytes, so you should work with byte arrays, not strings. Keep in mind that chars are not bytes in C# world.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜