Thanks Henrik,
I get the gist of what you have said, and I'll have a search for that expression. I must admit the syntax of VB is somewhat alien to me![]()
Thanks Henrik,
I get the gist of what you have said, and I'll have a search for that expression. I must admit the syntax of VB is somewhat alien to me![]()
Guys, one further thing... when there is no sensor connected the value for say Temperatures(0) will be 0. When present it sends the temperature as a three digit value, eg 25.7c would be sent as 257. I really need to send a zero value as 000 and not a single 0,
any ideas ?
Hi,
If you HSEROUT DEC3 Temperatures(0) it will write three digits, ie. 000 if the value is 0.
/Henrik.
Hi malc-c;
Hi use a function in VB, that does do the job, that you want, but you must send to VB more things;
You are sending 4 temperatures, i supose from 4 diferent sensors, 1 temperatura measure for each sensor.
So if you put something before sendig the temperatures to identify de sensor, like this for exemple;
You are Sending;
002610
002660
002680
002680
Ff you send;
S1002610
S2002660
S3002680
S4002680
The 2 first chars, are the ID of the sensor, and the 6 next chars are the temperature.
Now it's easy to separate them in VB, with the function "Mid",
On the event Data Received, you must do something like this;
You can use it too in a Select case, and you should put a try....cath too.Code:Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived Dim buffer As String buffer = SerialPort1.ReadExisting If Mid(buffer, 1, 2) = "S1" Then Label1.Text = Mid(buffer, 3, 6) ' label to show the temperature of 1º sensor End If If Mid(buffer, 1, 2) = "S2" Then Label2.Text = Mid(buffer, 3, 6) ' label to show the temperature of 2º sensor End If If Mid(buffer, 1, 2) = "S3" Then Label3.Text = Mid(buffer, 3, 6) ' label to show the temperature of 3º sensor End If If Mid(buffer, 1, 2) = "S4" Then Label4.Text = Mid(buffer, 3, 6) ' label to show the temperature of 4º sensor End If End Sub
If you don't understanding something, please tell me.
That sounds promising.
At the moment I've used Henriks suggestion to send three digits per record which helps with the formatting when the data is received by the application written by a chap from another forum who offered to help (he used liberty basic). However I'm trying to learn VB so your suggestion will help (I'm running two versions of PBP code side by side so I can develop either one)
At the moment the PIC sends data as
I assume if I need to prefix each section to apply the same code to make each set of three digits get placed in the right text box ?Code:Hserout [DEC3 Temperatures(0)] Hserout [DEC3 Temperatures(1)] Hserout [DEC3 Temperatures(2)] Hserout [DEC3 Temperatures(3)] HSEROUT [dec3 normtemp[0]] HSEROUT [dec3 normtemp[1]] HSEROUT [dec3 normtemp[2]] HSEROUT [dec3 normtemp[3]] Hserout [dec3 alarmlow[0]] Hserout [dec3 alarmlow[1]] Hserout [dec alarmlow[2]] Hserout [dec alarmlow[3]] Hserout [dec3 alarmhigh[0]] Hserout [dec3 alarmhigh[1]] Hserout [dec3 alarmhigh[2]] Hserout [dec3 alarmhigh[3]] hserout [#StartHour[0] DIG 1,#StartHour[0] DIG 0,#StartMin[0] DIG 1,#StartMin[0] DIG 0] hserout [#StartHour[1] DIG 1,#StartHour[1] DIG 0,#StartMin[1] DIG 1,#StartMin[1] DIG 0] hserout [#StartHour[2] DIG 1,#StartHour[2] DIG 0,#StartMin[2] DIG 1,#StartMin[2] DIG 0] hserout [#StartHour[3] DIG 1,#StartHour[3] DIG 0,#StartMin[3] DIG 1,#StartMin[3] DIG 0] hserout [#StopHour[0] DIG 1,#StopHour[0] DIG 0,#StopMin[0] DIG 1,#StopMin[0] DIG 0] hserout [#StopHour[1] DIG 1,#StopHour[1] DIG 0,#StopMin[1] DIG 1,#StopMin[1] DIG 0] hserout [#StopHour[2] DIG 1,#StopHour[2] DIG 0,#StopMin[2] DIG 1,#StopMin[2] DIG 0] hserout [#StopHour[3] DIG 1,#StopHour[3] DIG 0,#StopMin[3] DIG 1,#StopMin[3] DIG 0] Hserout [dec3 Droptemp[0]] Hserout [dec3 Droptemp[1]] Hserout [dec3 Droptemp[2]] Hserout [dec3 Droptemp[3]] hserout [#lightsetHR[0] DIG 1,#lightsetHR[0] DIG 0,#lightsetMN[0] DIG 1,#lightsetMN[0] DIG 0] hserout [#lightsetHR[1] DIG 1,#lightsetHR[1] DIG 0,#lightsetMN[1] DIG 1,#lightsetMN[1] DIG 0] hserout [#lightsetHR[2] DIG 1,#lightsetHR[2] DIG 0,#lightsetMN[2] DIG 1,#lightsetMN[2] DIG 0] hserout [#lightsetHR[3] DIG 1,#lightsetHR[3] DIG 0,#lightsetMN[3] DIG 1,#lightsetMN[3] DIG 0] hserout [#lightoffHR[0] DIG 1,#lightoffHR[0] DIG 0,#lightoffMN[0] DIG 1,#lightOFFMN[0] DIG 0] hserout [#lightoffHR[1] DIG 1,#lightoffHR[1] DIG 0,#lightoffMN[1] DIG 1,#lightOFFMN[1] DIG 0] hserout [#lightoffHR[2] DIG 1,#lightoffHR[2] DIG 0,#lightoffMN[2] DIG 1,#lightOFFMN[2] DIG 0] hserout [#lightoffHR[3] DIG 1,#lightoffHR[3] DIG 0,#lightoffMN[3] DIG 1,#lightOFFMN[3] DIG 0]
Also how would I modify the PBP code to send S1, S2 etc as part of the data, would it be "hserout [S1,dec3 temperatures[0]]
Last edited by malc-c; - 22nd August 2010 at 10:38. Reason: forgot to ask about the pbp side
Guys and Gals, need your help.
Through an other forum I've had the offer of some assistance from one of it's members. He has written an application (I believe it's in Liberty Basic) and so far we've got it to read the data stream from the PIC and display it in boxes
We're now trying to get the application to send new values back to the PIC and this is where I need some guidance.
This is how he is sending data from the application
The PBP code contains the following sectionsThis version will send only the target temperatures.
It should send "S" followed by carriage return
Then it should send 12 digits (4 sensors * 3 digits) followed by carriage return
It should then wait 3 seconds to give you time to process stuff, then it will query everything and expect all 108 characters back.
It will then wait 4 seconds, and display what it received.
I've removed the original code that DT had written which displayed PID info via hyperterminal and replaced it withCode:;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - FOR TempWD = 0 TO 1000 IF RCIF THEN GOSUB Term_RX PAUSE 1 NEXT TempWD ;- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
But when the update button is clicked on the PC app the PIC appears to lock up.Code:Term_RX: HSERIN [Char] SELECT CASE Char CASE "S","s" Hserin [DEC3 normtemp(0)] Hserin [DEC3 normtemp(1)] Hserin [DEC3 normtemp(2)] Hserin [DEC3 normtemp(3)] END SELECT return
I would welcome suggestions on what I'm doing wrong, or what's needed to work with the protocol my friend has evolved.
For reference here is the section that Darrel coded which used to set just one thermostat channel (ie would send just one value ) at a time
I've got a routine within the code that contains SetPoints(0)=normtemp(0) etc so please don't get confused over the actual variables.Code:Term_RX: HSERIN [Char] SELECT CASE Char CASE "S","s" ' Enter Setpoint X=1 : Y=22 : GOSUB MoveCursor HSEROUT ["Enter SetPoint ... (340=34.0",$F8,"): "] HSERIN [DEC SetPoints(EditChannel)] GOSUB TerminalMenu SELECT CASE EditChannel CASE 0 : Bvar = EE_SetPoint1 CASE 1 : Bvar = EE_SetPoint2 CASE 2 : Bvar = EE_SetPoint3 CASE 3 : Bvar = EE_SetPoint4 END SELECT WRITE Bvar, WORD SetPoints(EditChannel)
Instead, try:This version will send only the target temperatures.
It should send "S" followed by carriage return
Then it should send 12 digits (4 sensors * 3 digits) followed by carriage return
It should then wait 3 seconds to give you time to process stuff, then it will query everything and expect all 108 characters back.
It will then wait 4 seconds, and display what it received
Then in your main loop add something like:It should send "S"(single character, no carriage return)
It should wait for the PIC to reply with "K" (or your favorite acknowledge character)
Then it should send 12 digits (4 sensors * 3 digits) followed by carriage return
It should then wait 3 seconds to give you time to process stuff, then it will query everything and expect all 108 characters back.
It will then wait 4 seconds, and display what it received
nTest var byte
I suspect the PIC appears to lock because it misses a byte. The above slows everything just a little and uses a positive acknowledgement to make sure everything is set.Code:If PIR1.5 = 1 Then 'check to see if there is data in the serial buffer HSERIN[nTest] if nTest = "S" then HSEROUT["K"] 'Let the PC know to start sending data HSERIN[....all the rest of your stuff...] endif endif
Hope this helps somehow...
Best Regards,
Paul
Bookmarks