Perhaps someone could clear up a slight problem I am having with Program Editor (ver 5.5.1).
I am using an 18M2 with an NKM coder/decoder to send text strings to 6 different 08M2s (with NKM decoder also). I am using the serout and serin command to do this. My problem is concerned with the “changing” of decimal digits to ASCII during the transmission process. I know the digits don’t change as such, but when you look at what is transmitted using the AXE213 it doesn’t seem to correspond with reality.
I have six timers connected to pins B.1 to B.6 of the 18M2. The timers are the ones used in electrical socket timers (minus the high voltage AC circuitry of course). When a timer is ON each pin on the 18M2 sees 5V and when a timer is OFF the corresponding pin sees 0V. I read each timer state, using the readadc command, into a variable (variable b6 to b11) as follows. Only first two timers shown for brevity. You don’t need to follow the code, only the text string in the serout line is important:
Transmit Code
timer1:
readadc B.1,b6
if b6<80 then timer1off ’80 is picked just because it somewhere between 0 and 256 and hence signifies that a voltage is present
if b6>80 then timer1on
timer2:
readadc B.2,b7
if b7<80 then timer2off
if b7>80 then timer2on
timer1off:
serout B.0,N2400,("10345678")
goto timer2
timer1on:
serout B.0,N2400,("11345678")
goto timer2
timer2off:
serout B.0,N2400,("20345678")
goto timer1
timer2on:
serout B.0,N2400,("21345678")
goto timer1
As you can see EACH 08M2 receives all the text strings but will only respond if the text string has the appropriate first digit identifier. See receiving code below.
As you can see from the code the first digit of the string is used to identify the number of the timer and the second digit is used to give the timer state, 0 for OFF and 1 for ON.
I then received this data on my receivers, the 08M2s. Unfortunately, I couldn’t get my receiving code on the 08M2s to work. I then connected up my AXE 213 to my laptop and saw that I was receiving EXACTLY what I was transmitting. If 11345678 was transmitted, I saw 11345678 using the AXE213 on my laptop.
The receiving code I used is below (code for 1st receiver only shown and much shortened): The output of each 08M2 powers a solenoid valve through pin0 and pin4 going high and low alternately. Again no need to follow code exactly except for the serin command where each digit of the transmitted string is put into the variables b0 to b7 and the if statements.
I eventually solved the problem. I did not realise that each digit in the text string was transmitted as ASCII. When I substituted 48 for 0 and 49 for 1 in the code, everything worked perfectly.
Is there a solution to this apparent discrepancy. Although I have got around the problem, I now want to move my project a step further by incorporating a thermistor onto each input on the 18M2. This means that there will be a need to transmit an identifier plus a variable between 0 and 256 to each receiver. Has anybody got any ideas on how to do this and how I can see what is really received by the 08M2s by using my AXE213?
Thanks in advance for any suggestions.
Receive code
symbol trg1 = 0 'assumes pin 0 (leg 7)for solenoid trigger to pin 1 of K2 Relay
symbol trg2 = 4 'assumes pin 4 (leg 3) for solenoid trigger to pin 1 of relay K1
start:
low trg1 'turn off pin0
low trg2 'turn off pin4
serin 3,N2400,b0,b1,b2,b3,b4,b5,b6,b7
if b0<> 1 then start
if b0=1 and b1=1 then coilon
if b0=1 and b1=0 then coiloff
goto start
coiloff:
high trg1 'turns off solenoid
low trg2 'turns off solenoid
goto start 'go back to the beginning
coilon:
low trg1 'turns on solenoid
high trg2 'turns on solenoid
prev2=1
low trg2
goto start
I am using an 18M2 with an NKM coder/decoder to send text strings to 6 different 08M2s (with NKM decoder also). I am using the serout and serin command to do this. My problem is concerned with the “changing” of decimal digits to ASCII during the transmission process. I know the digits don’t change as such, but when you look at what is transmitted using the AXE213 it doesn’t seem to correspond with reality.
I have six timers connected to pins B.1 to B.6 of the 18M2. The timers are the ones used in electrical socket timers (minus the high voltage AC circuitry of course). When a timer is ON each pin on the 18M2 sees 5V and when a timer is OFF the corresponding pin sees 0V. I read each timer state, using the readadc command, into a variable (variable b6 to b11) as follows. Only first two timers shown for brevity. You don’t need to follow the code, only the text string in the serout line is important:
Transmit Code
timer1:
readadc B.1,b6
if b6<80 then timer1off ’80 is picked just because it somewhere between 0 and 256 and hence signifies that a voltage is present
if b6>80 then timer1on
timer2:
readadc B.2,b7
if b7<80 then timer2off
if b7>80 then timer2on
timer1off:
serout B.0,N2400,("10345678")
goto timer2
timer1on:
serout B.0,N2400,("11345678")
goto timer2
timer2off:
serout B.0,N2400,("20345678")
goto timer1
timer2on:
serout B.0,N2400,("21345678")
goto timer1
As you can see EACH 08M2 receives all the text strings but will only respond if the text string has the appropriate first digit identifier. See receiving code below.
As you can see from the code the first digit of the string is used to identify the number of the timer and the second digit is used to give the timer state, 0 for OFF and 1 for ON.
I then received this data on my receivers, the 08M2s. Unfortunately, I couldn’t get my receiving code on the 08M2s to work. I then connected up my AXE 213 to my laptop and saw that I was receiving EXACTLY what I was transmitting. If 11345678 was transmitted, I saw 11345678 using the AXE213 on my laptop.
The receiving code I used is below (code for 1st receiver only shown and much shortened): The output of each 08M2 powers a solenoid valve through pin0 and pin4 going high and low alternately. Again no need to follow code exactly except for the serin command where each digit of the transmitted string is put into the variables b0 to b7 and the if statements.
I eventually solved the problem. I did not realise that each digit in the text string was transmitted as ASCII. When I substituted 48 for 0 and 49 for 1 in the code, everything worked perfectly.
Is there a solution to this apparent discrepancy. Although I have got around the problem, I now want to move my project a step further by incorporating a thermistor onto each input on the 18M2. This means that there will be a need to transmit an identifier plus a variable between 0 and 256 to each receiver. Has anybody got any ideas on how to do this and how I can see what is really received by the 08M2s by using my AXE213?
Thanks in advance for any suggestions.
Receive code
symbol trg1 = 0 'assumes pin 0 (leg 7)for solenoid trigger to pin 1 of K2 Relay
symbol trg2 = 4 'assumes pin 4 (leg 3) for solenoid trigger to pin 1 of relay K1
start:
low trg1 'turn off pin0
low trg2 'turn off pin4
serin 3,N2400,b0,b1,b2,b3,b4,b5,b6,b7
if b0<> 1 then start
if b0=1 and b1=1 then coilon
if b0=1 and b1=0 then coiloff
goto start
coiloff:
high trg1 'turns off solenoid
low trg2 'turns off solenoid
goto start 'go back to the beginning
coilon:
low trg1 'turns on solenoid
high trg2 'turns on solenoid
prev2=1
low trg2
goto start