![]() |
Usage of serial port on cRio
1 Attachment(s)
We're having a lot of difficulty using the serial port on the cRio to interface with devices.
When running some very simple code (I sure hope I'm just doing something wrong) - the cRio will read some data (slowly) and then crash. Code:
virtual void TeleopPeriodic() { |
Re: Usage of serial port on cRio
I don't have Wind River in front of me at the moment so I can't verify the com class especially the Read method, but my instinct tells me that you declare buffer as a "char *" which means there is no buffer associated with it. buffer is an uninitialized pointer. If the Read method is going to put bytes into buffer, it is going to trash random memory locations.
I could be wrong ;) |
Re: Usage of serial port on cRio
Quote:
|
Re: Usage of serial port on cRio
Quote:
Nope, you are 100% correct. They have declared/reserved no storage. Change char *buffer to char buffer[X] where X is big enough to hold the data. It should work then but it is a bit of a kludge, you probably want a bigger buffer declared as a global or allocate the memory so it is not on the stack (as all local variables are). HTH |
Re: Usage of serial port on cRio
Of course it looks correct (at least before it crashed). Imagine the buffer pointer is pointing to some random memory, so the Read method will start copying the bytes to the random location. Your print loop will also print the bytes from this random location. But what is this random location anyway? What if the random location contains the return address of your function (which is very likely)? So at the end of your function when you are returning to the caller, since the return address is trashed, you returned to la la land, thus crashed.
|
Re: Usage of serial port on cRio
Aha, this worked. Feeling quite silly now but thanks!
|
| All times are GMT -5. The time now is 13:32. |
Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi