week4

Cobox communication

09/28

I finally got numbers on hyperterminal screen through a server, I want to keep how I did it. At first, I found that the configuration I set up last week was wrong. Because I need to use the last 3 digits of my IP address(128.122.151.108), which is given to me, into the remote port number. And in the telnet stage screen I need to put 'java CoboxServer 10108'. That is a clue for talking! Then I want to make my circuit talk through server to make my LEDs light up. But I found it needs many things to think about, because I have to modify my BX24 code. I tried to do it, but I realized that I could receive valus from cobox, And I need to know how to communicate using serial input. It looks not so easy for now. I am going to put more time on this.

 

09/28/03 I am trying to modify Tom's code below a little bit to make 7LEDs light up.

' set up input and output buffers in memory:
dim outputBuffer(1 To 50) as byte
dim inputBuffer(1 To 20) as byte

' variables for dealing with incoming serial data:
dim gotaByte as boolean
dim dataByte as byte
dim dataValue as byte

' strings for sending out through the CoBox:
dim sendString as String
dim connectString as String

' variables for dealing with the ADC:
dim adcval as integer
dim byteval as byte

' constants for the serial port and the ADC:
const serOutPin as byte = 11
const serInPin as byte = 12

Sub main()

call delay(1.0) ' start program with a half-second delay

' set up serial port:
call defineCom3(serInPin, serOutPin, bx1000_1000)

' open the input and output buffers:
call openQueue(outputBuffer, 50)
call openQueue(inputBuffer, 20)
call openCom(3, 9600, inputBuffer, outputBuffer)

' main loop:
do
' read the value of the ADC on pin 20, convert to a byte:
adcval = getADC(20)
byteval = cByte(adcVal / 4)

' check for incoming serial data:
call serialCheck()
loop
End Sub


sub serialCheck()
' Find out if anything is in the queue.
gotaByte = statusQueue(inputBuffer)

' If there is data in the input buffer,
' get the first byte of it:

if (gotaByte = true) then
' there's data available: read it here
call getQueue(inputBuffer, dataByte, 1)

' do stuff in response to serial data here
call parseCharacter()
end If
end sub

sub parseCharacter()
dim i as byte ' local variable for for-next counter

' convert the ascii value of 0-9 to a numeric value
' (e.g. ascii "0" = 48)
'dataValue = dataByte - 48

if (dataByte>=0) and (dataByte < 25)
dataValue =0
elseif (dataByte>=25) and (dataByte < 50)
dataValue =1
elseif (dataByte>=50 and (dataByte < 75)
dataValue =2
elseif (dataByte>=75) and (dataByte < 100)
dataValue =3
elseif (dataByte>=100) and (dataByte < 125)
dataValue =4
elseif (dataByte>=125) and (dataByte < 150)
dataValue =5
elseif (dataByte>=150) and (dataByte < 175)
dataValue =6
elseif (dataByte>=175) and (dataByte < 200)
dataValue =7
elseif (dataByte>=200) and (dataByte < 225)
dataValue =8
elseif (dataByte>=225) and (dataByte < 255)
dataValue =9

' iterate over the pins, turn on the one asked for,
' and turn the others off:
for i = 13 to 19
if dataValue + 12 = i then
call putPin(i,1)
else
call putPin(i,0)
end if
next

' if we get "9", send the ADC message.
' otherwise, echo what we got:
if dataValue = 9 then
call sendADCVal()
else
call putQueue(outputBuffer, dataByte, 1)
end if

end sub

sub sendADCval()
' format a message with the ADC value at the end:
sendString = "ADC" & chr(byteVal)
call putQueueStr(outputBuffer, sendString)
end sub

----------------------------------------------

related page of this code is here.

'******Tom Igoe's BX code to make 7 LEDs light up.**********

'Byte value sent LED lit
'0 none
'1 pin 13
'2 pin 14
'3 pin 15
'4 pin 16
'5 pin 17
'6 pin 18
'7 pin 19

' set up input and output buffers in memory:
dim outputBuffer(1 To 50) as byte
dim inputBuffer(1 To 20) as byte

' variables for dealing with incoming serial data:
dim gotaByte as boolean
dim dataByte as byte
dim dataValue as byte

' strings for sending out through the CoBox:
dim sendString as String
dim connectString as String

' variables for dealing with the ADC:
dim adcval as integer
dim byteval as byte

' constants for the serial port and the ADC:
const serOutPin as byte = 11
const serInPin as byte = 12

Sub main()

call delay(1.0) ' start program with a half-second delay

' set up serial port:
call defineCom3(serInPin, serOutPin, bx1000_1000)

' open the input and output buffers:
call openQueue(outputBuffer, 50)
call openQueue(inputBuffer, 20)
call openCom(3, 9600, inputBuffer, outputBuffer)

' main loop:
do
' read the value of the ADC on pin 20, convert to a byte:
adcval = getADC(20)
byteval = cByte(adcVal / 4)

' check for incoming serial data:
call serialCheck()
loop
End Sub


sub serialCheck()
' Find out if anything is in the queue.
gotaByte = statusQueue(inputBuffer)

' If there is data in the input buffer,
' get the first byte of it:

if (gotaByte = true) then
' there's data available: read it here
call getQueue(inputBuffer, dataByte, 1)

' do stuff in response to serial data here
call parseCharacter()
end If
end sub

sub parseCharacter()
dim i as byte ' local variable for for-next counter

' convert the ascii value of 0-9 to a numeric value
' (e.g. ascii "0" = 48)
dataValue = dataByte - 48

' iterate over the pins, turn on the one asked for,
' and turn the others off:
for i = 13 to 19
if dataValue + 12 = i then
call putPin(i,1)
else
call putPin(i,0)
end if
next

' if we get "9", send the ADC message.
' otherwise, echo what we got:
if dataValue = 9 then
call sendADCVal()
else
call putQueue(outputBuffer, dataByte, 1)
end if

end sub

sub sendADCval()
' format a message with the ADC value at the end:
sendString = "ADC" & chr(byteVal)
call putQueueStr(outputBuffer, sendString)
end sub

-------------------------------------------------------

' set up input and output buffers in memory:
dim outputBuffer(1 To 50) as byte
dim inputBuffer(1 To 20) as byte

' variables for dealing with incoming serial data:
dim gotaByte as boolean
dim dataByte as byte
dim dataValue as byte

' strings for sending out through the CoBox:
dim sendString as String
dim connectString as String

' variables for dealing with the ADC:
dim adcval as integer
dim oldADCVal as integer
dim byteval as byte
'dim receiveVal as integer
const ADCThreshold as integer = 10

' constants for the serial port and the ADC:
const serOutPin as byte = 11
const serInPin as byte = 12

Sub main()

call delay(1.0) ' start program with a half-second delay

' set up serial port:
call defineCom3(serInPin, serOutPin, bx1000_1000)

' open the input and output buffers:
call openQueue(outputBuffer, 50)
call openQueue(inputBuffer, 20)
call openCom(3, 9600, inputBuffer, outputBuffer)

' main loop:12
do
' read the value of the ADC on pin 20, convert to a byte:
adcval = getADC(20)
byteval = cByte(adcVal \ 4)

' if the ADC has changed by more than the threshold,
' then send it out the serial port:
if abs(ADCVal - oldADCVal) > ADCThreshold then
call sendADCval()
oldADCVal = ADCVal
call receiveADCVal()
end if

loop
End Sub

sub sendADCval()
' format a message with the ADC value at the end:
'sendString = "ADC= " & cstr(byteVal) & chr(10) & chr(13)
sendString = cstr(byteVal) & chr(10) & chr(13)
call putQueueStr(outputBuffer, sendString)
end sub

sub receiveADCval()
if serInPin got some value
call putPin (16, 0)
else
call putPin (16, 1)
end if
end sub

 

Journal Index