tags:

views:

30

answers:

1

Hi all,

I am doing a project with 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

A: 

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.

Dialecticus