PDA

View Full Version : Simple question about Serin..



Donat
- 11th March 2008, 12:29
Hello,

I'm writing some code for a couple of 16F628's on a RS485 network..

I'm using the serin command ;



databyte VAR BYTE ' Recieved command/request
ADRESS VAR BYTE ' Adres selected by dip switches

serin PortB.1,t9600,[WAIT (ADRESS),databyte]


The adress is selected by an 8 bit dipswitch on the slave pcb.
The only way a slave can be adressed is by its unique adress.

I now want to implement a broadcast adress to..

I was wondering if there is a way so that the slave only completes the serin command if the "adress" statement OR the "broadcast adress" is forfilled ?

I've tried ;


databyte VAR BYTE ' Recieved command/request
ADRESS VAR BYTE ' Adres selected by dip switches
BROADCAST CON %11111111 ' Broadcast adress

serin PortB.1,t9600,[WAIT (ADRESS OR BROADCAST),databyte]


But i knew this would be to easy..

Any help would be greatly appreciated.

Regards Donat

mackrackit
- 11th March 2008, 20:11
Looks like your syntax is the problem.


serin PortB.1,t9600,[ADRESS],databyte


It waits for whatever is in the []

You are coded more for SERIN2

What 485 converter are you using?

Donat
- 12th March 2008, 08:24
Sorry, thats my mistake

It was originally a serin2 command..

But it's about waiting for one qualifier OR the other i'm trying to implement.

It should store the recieved byte once the slave's individual adress (qualifier 1) or the broadcast adress (qualifier 2) is forfilled.

Maybe i should just divide it up in two different commands..

Thank you

Donat
- 12th March 2008, 11:48
The RS485 Tranciever i am using is the TI SN65HVD06D 1/8 Load, 10Mbps

http://focus.ti.com/lit/ds/symlink/sn65hvd06.pdf

rwskinner
- 12th March 2008, 12:13
'Instead of waiting, grab the first byte and see if it's for your ID or Broadcast then
'if so collect the rest of the bytes

HSerIn Timeout,ExitRx,[BufRX(0)]
If ((BufRx[0] = MyID) or (BufRx[0] = BroadCast)) then
For Cnt = 1 to 7
HSerIn Timeout,ExitRx,[BufRX(Cnt)]
Next Cnt
EndIf


WAIT actually has to look at each byte as well in order to know weather to start storing or not.

Jerson
- 12th March 2008, 16:16
You can use Skinner's technique which is easy enough or consider this.

If your command sequence is terminated with a known value like CR or CRLF which is the norm in most cases, your job becomes easier. What you have to do is just collect the data and buffer it till you hit the CR. Then, check the packet for ID and process accordingly. This is how I do it in my products
ID xxxx CR
If the packet is not yours and not a broadcast, discard it.

rwskinner
- 12th March 2008, 16:26
Yes, but if he is doing something like modbus for instance, he only has the node#, correct number of bytes to collect, and then the timeout or Silent time.

Then he would have to verify the data with a crc check before proceding, this of course is if he is using MB RTU and Not ASCII, or his own home grown protocol.

Only reason I menioned modbus is because he mentioned a 485 network, Node ID, and Broadcast so it kind of sounds like it.

Richard