Recieving serial in C ?
Yet another one of my questions about my project with the VRStamp...
Im interfacing with an X10 CM11a. The CM11a operates at 4800bps serial.
When it recieves· dec 195, it outputs dec 90, then 10 bytes of stored information.
I recieve this information flawlessly every time with either the debug terminal, or the BS2. With the VRS coded in C, I get some information, but other is bad.
Example, I would recieve (dec)
9
170
98
99
98
99
98
99
98
99
I seem to always get the first two bytes right, but very often, if not every time, one of the last 8 bytes is 255 and the one before or after it is 19. When snooping with the debug window, I still see the proper code across the line, but the VRS stores the wrong information in the input[noparse][[/noparse]10] array.
Ideas?
void ReadIn(int deb)
{
·int x;
· _Init232();
··· if (_GetBaudRate() != BAUD4800)
··· {······· _SetBaudRate(BAUD4800);··· }
····· for (x=0;x<10;x++)
····· input[noparse][[/noparse]x]=0;
······ input[noparse][[/noparse]0]=_Wait232();
······ if (input[noparse][[/noparse]0] == 90) {
········ _DelayMilliSecs(2);
········ _Put232 (195);
········ input[noparse][[/noparse]0]=_Wait232();
········ for (x = 1;x <= input[noparse][[/noparse]0]; x++)
··········· input[noparse][[/noparse]x]=_Wait232();
···········
··························· }
· _PlaySnd(0,0,32);
· _Idle232();···········
I added the input clearing code, trying to fix this
The VRS interfaces with the serial line with a standard msx232 interface.
Here is the code for my BS2P40 that works flawlessly
AUXIO
SERIN p1, baud,[noparse][[/noparse]WAIT(90)] 'wait for the "0x90" - attention code.
PAUSE 250··············· 'as the program will hang here until it recieves a code
SEROUT 0, baud, [noparse][[/noparse]195]··· 'tell the interface to transmit its data
FOR x=0 TO result(0)···· 'populate up to 10 bytes of data
SERIN p1,baud, [noparse][[/noparse]result(x)]'place each byte in a seqential array of result
NEXT
Post Edited (GICU812) : 11/23/2008 7:16:07 PM GMT
Im interfacing with an X10 CM11a. The CM11a operates at 4800bps serial.
When it recieves· dec 195, it outputs dec 90, then 10 bytes of stored information.
I recieve this information flawlessly every time with either the debug terminal, or the BS2. With the VRS coded in C, I get some information, but other is bad.
Example, I would recieve (dec)
9
170
98
99
98
99
98
99
98
99
I seem to always get the first two bytes right, but very often, if not every time, one of the last 8 bytes is 255 and the one before or after it is 19. When snooping with the debug window, I still see the proper code across the line, but the VRS stores the wrong information in the input[noparse][[/noparse]10] array.
Ideas?
void ReadIn(int deb)
{
·int x;
· _Init232();
··· if (_GetBaudRate() != BAUD4800)
··· {······· _SetBaudRate(BAUD4800);··· }
····· for (x=0;x<10;x++)
····· input[noparse][[/noparse]x]=0;
······ input[noparse][[/noparse]0]=_Wait232();
······ if (input[noparse][[/noparse]0] == 90) {
········ _DelayMilliSecs(2);
········ _Put232 (195);
········ input[noparse][[/noparse]0]=_Wait232();
········ for (x = 1;x <= input[noparse][[/noparse]0]; x++)
··········· input[noparse][[/noparse]x]=_Wait232();
···········
··························· }
· _PlaySnd(0,0,32);
· _Idle232();···········
I added the input clearing code, trying to fix this
The VRS interfaces with the serial line with a standard msx232 interface.
Here is the code for my BS2P40 that works flawlessly
AUXIO
SERIN p1, baud,[noparse][[/noparse]WAIT(90)] 'wait for the "0x90" - attention code.
PAUSE 250··············· 'as the program will hang here until it recieves a code
SEROUT 0, baud, [noparse][[/noparse]195]··· 'tell the interface to transmit its data
FOR x=0 TO result(0)···· 'populate up to 10 bytes of data
SERIN p1,baud, [noparse][[/noparse]result(x)]'place each byte in a seqential array of result
NEXT
Post Edited (GICU812) : 11/23/2008 7:16:07 PM GMT
Comments
9
170
98
99
98
99
98
99
98
99
I got
9
170
98
99
98
19
255
98
19
255
again
9
170
98
99
98
99
98
51
255
98
again
9
170
255
99
98
99
98
255
99
101
No one? Nothing?
I added my BS2 code that works flawlessly.