Up until two weeks ago I had never tried coding on the ardunio platform, having used PicBASIC PRO to develop small projects in the past. However, after a lot of badgering from a friend I agreed to giving it a go, and over the past couple of weeks have turned the examples into something that might replace an old PIC based project.
One thing I need to to is communicate with a PC application. This is done in simple terms, in that the PC applications connects via serial to the PIC. The PIC code checks each time the code loops to see if there is a character in the buffer. If it finds a Q it jumps to a subroutine that sends a long string of data to the PC. If it finds an S then it jumps to a subroutine that awaits a similar long string and places it into the variables.
The process is handled by a case statement
IF RCIF=1 THEN GOto coms ; Check to see id PC application connected coms: HSERIN [nTest] SELECT CASE nTest CASE "Q" ; if Q then send data to PC Goto Term_TX CASE "S" ; if S then receive data from PC goto Term_RX end select
With the two subrotines
Term_RX: For Counter = 0 to 3 HSERIN 1000, RX_Bombed, [DEC3 NormTemp[Counter]] NEXT For Counter = 0 to 3 HSERIN 1000, RX_Bombed, [DEC3 AlarmLow[Counter]] NEXT etc etc Term_TX: Hserout [DEC3 Temperatures(0)] Hserout [DEC3 Temperatures(1)] Hserout [DEC3 Temperatures(2)] Hserout [DEC3 Temperatures(3)] HSEROUT [dec3 normtemp] HSEROUT [dec3 normtemp] HSEROUT [dec3 normtemp] HSEROUT [dec3 normtemp] Hserout [dec3 alarmlow] Hserout [dec3 alarmlow] Hserout [dec3 alarmlow] Hserout [dec3 alarmlow] etc etc etc
No I want to replicate this using my mega2560 with the default serial port
I've found details in the wiki that allow me to replicate the PBP DEC3 command to send data to just one decimal place, for example, the PC application is expecting 123 for a temperature reading of 12.3, but I'm confused as to which command "Serial.event ??" to do the initial checking for a Q or an S in the buffer, and how to jump out of the main loop to a subroutine that will accept the stream or build it.
The serial stream is 132 digits long. So for example where the four temperature probes read 23.4, 23.7, 23.6 and 24.1 the start of the string will be "234237236241" It then continues in the same way for the other variables. When the PC application received the string, it then splits the data up into text boxes, and placed the decimal back in, so text box1 = 23.4, text box2 23.7 etc
Sorry for the long winded post, but I wanted to include as much information as possible in order to help you guys understand what I'm looking for