mirzao
Active member
Hi,
I wrote a code to read from more than 1 serial device and write the response in a textbox.
each device will return a different set of code but sometime it doesn't.There are more than 20 codes (e.g502, 304, 703 etc) and each code has different meaning.The string that I get from 1 device is something like this,
strs
715 304 607
FLASH(0)RAM>
My application will continuously communicate with the device unless someone press the stop button.What I want to do is to split the code and put into their categories
(715 as speedloss, 304 as unscheduledTTime)and increment the variables.If in the second loop, it still finds "715", it will calculate how long the code appears by
multiply it with the total time to complete 1 loop (dt). if in the 3rd loop the code is not there anymore, I want the cell displaying "0". And if the code appears again in the next loop,it will add to the previous total time.The problem is I have not much experience in programming and there are lots of things I need to learn. So if you guys have any suggestion , code samples or advice to make my code better, please let me know. Many thanks in advance
The whole representation of my code is as following :
I wrote a code to read from more than 1 serial device and write the response in a textbox.
each device will return a different set of code but sometime it doesn't.There are more than 20 codes (e.g502, 304, 703 etc) and each code has different meaning.The string that I get from 1 device is something like this,
strs
715 304 607
FLASH(0)RAM>
My application will continuously communicate with the device unless someone press the stop button.What I want to do is to split the code and put into their categories
(715 as speedloss, 304 as unscheduledTTime)and increment the variables.If in the second loop, it still finds "715", it will calculate how long the code appears by
multiply it with the total time to complete 1 loop (dt). if in the 3rd loop the code is not there anymore, I want the cell displaying "0". And if the code appears again in the next loop,it will add to the previous total time.The problem is I have not much experience in programming and there are lots of things I need to learn. So if you guys have any suggestion , code samples or advice to make my code better, please let me know. Many thanks in advance
The whole representation of my code is as following :
sub doloop()
Do
For i=0 to 20
'Open port
'Write command to port
Try
'Read
'write to textbox
catch
'Do nothing
End Try
Try
myStat = TextBox1.Lines(TextBox1.Lines.Length ).Split(" "c)
'For o = LBound(mystringarray) To UBound(mystringarray) - 1
For o = LBound(myStat) To UBound(myStat) - 1
Select Case myStat(o)
'Select Case mystringarray(o)
Case "607", "401", "402", "503"
idletime += 1
excelWorksheet.Range("B" & oCP.Port).Value = (idletime - 1) * dt
End If
Case "70E", "405", "40A", "706" ', "305"
tempsetup += 1
excelWorksheet.Range("C" & oCP.Port).Value = (tempsetup - 1) * dt
Case "716", "507"
lotsetuploss += 1
excelWorksheet.Range("D" & oCP.Port).Value = (lotsetuploss - 1) * dt
Case "301", "304", "306", "700", "701", "702", "703", "704", "70B", "70D", "710"
unscheduledDTime += 1
excelWorksheet.Range("E" & oCP.Port).Value = (unscheduledDTime - 1) * dt
Case "30A", "715"
speedloss += 1
excelWorksheet.Range("F" & oCP.Port).Value = (speedloss - 1) * dt
End Select
Next 'code read
Catch ex as exception
'Listbox.Items.Add("Unable to read from port")
End Try
'Close port
Next 'next port
Loop