![]() |
|
#1
|
|||
|
|||
problem with reading bits from a remote deviceHello all,
i am programming a micro controller with C programming language. I have successfully implemented the MODBUS communication protocol but now I have encountered a bug. Let me explain how does the communication works: from the PC i send a request to read multiple coils (bits), this request tells the remote device the starting address (the address from which we want to start the reading of coils) and the quantity of bits. In the program I calculate from the starting address the starting element of the char array, and then I calculate the number of bytes from the quantity of bits. Then I make a loop and cycle it until the number of sending bits is equal to the number of quantity of bytes. The code looks something like this: CPP / C++ / C Code:
The code works like this: I wrote fixed values in the array char from byts[0] = 0xff; to byts[3] = 0xff;. When I wrote the 4th byte of array the rezult was strange, because both the byte[4] was also affected with the number but instead of setting on 0xff , it set to 0xf7. I also tried to set one bit at the time, and I found out that when I set the first bit of the byte[3] array char both the first and the last were changed from logic 0 to logic 1. When I changed the second bit of byte[3] it change its second bit to logic 1 and the first bit on byte[4]. One last thing when I observe the reading of bits one byte at the time it works fine, maybe because I can't see the effect of the other array of char elements. I have tested this code with Visual C++ 2008 and it works, everything is at the right place and this is why I can understand why on the micro controller doesn't work. Anyone has any idea about this? Best Regards, BoSCHoW. |
|||
|
#2
|
|||
|
|||
Re: problem with reading bits from a remote deviceHi,
Since the code happens to work correctly as expected with VC++ alone My guess is that it has got something got to do with how the variables are getting read or intialized ( array of char byts ). Quote:
is it a single dimension array ?. char byte[0] can store only one character in the array element numbered '0' ( you are storing 0xff).Can you show a snippet of your code where you do this intialization of bytes. Regards, Rajeev |
|
#3
|
|||
|
|||
Re: problem with reading bits from a remote deviceThe system (API) was already made, another developer made it, I just wrote the application on top of it. So the guy that made the system gave me a pointer that points to the non volatile data memory and I use this pointer to access to this registers...
And I think that is nothing wrong if I declare this nvvar (non volatile memory) area like this: CPP / C++ / C Code:
I have tested the application, one byte at the time. Best regards, BoSCHoW. |
Recent GIDBlog
Problems with the Navy (Officers) by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| contents of .txt file into 2D array | anirudhroxrulz | C Programming Language | 4 | 10-Apr-2008 22:45 |
| BMP image on matrix load | nemo | C++ Forum | 21 | 17-Dec-2007 23:04 |
| Hard drive/CPU Diagnoses Issues | binarybug | Computer Hardware Forum | 1 | 22-Jan-2007 19:23 |
| D3D error when running fullscreen games/programs - help?! | daa709 | Computer Hardware Forum | 4 | 01-Jul-2005 08:03 |
| Problem with reading from file descriptor | philea_mate | C Programming Language | 2 | 12-Apr-2005 02:59 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The