Avatar billede syncro Nybegynder
14. oktober 2003 - 10:55 Der er 8 kommentarer og
1 løsning

Send og læs næste komando over RS232

Hej
Er ved at lave et program der skal modtage og sende data fra et instrument på en com-port.
Programmet skal køre i et loop indtil man trykker stop
Mit spørgsmål er : Hvordan sender og modtager jeg næste komando fx. MSComm1.Output = "RI" + Chr$(13) + Chr$(10)
og modtager ISO:99/20/5

Programmet ser sådan ud nu:

Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)

Private Sub Start_Click()

MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True

Do
MSComm1.Output = "RC" + Chr$(13) + Chr$(10)

Do
dummy = DoEvents()
Loop Until MSComm1.InBufferCount >= 62
Label1.Caption = MSComm1.Input
Label2.Caption = Val(Mid$(Label1.Caption, 56, 8))
Label3.Caption = Val(Mid$(Label1.Caption, 48, 8))
Label4.Caption = Val(Mid$(Label1.Caption, 40, 8))
Label5.Caption = Val(Mid$(Label1.Caption, 28, 8))
Label6.Caption = Val(Mid$(Label1.Caption, 20, 8))
Label7.Caption = Val(Mid$(Label1.Caption, 10, 8))

Label8.Caption = (Label2.Caption * 0.1)
Label9.Caption = (Label3.Caption * 0.01)
Label10.Caption = (Label4.Caption * 0.001)
Label11.Caption = (Label5.Caption * 0.0001)
Label12.Caption = (Label6.Caption * 0.00001)
Label13.Caption = (Label7.Caption * 0.000001)



CENTUM1.StationName = "HIS0164"
a = CENTUM1.PutTagData(Text1.Text, Label8.Caption)
a = CENTUM1.PutTagData(Text2.Text, Label9.Caption)
a = CENTUM1.PutTagData(Text3.Text, Label10.Caption)
a = CENTUM1.PutTagData(Text4.Text, Label11.Caption)
a = CENTUM1.PutTagData(Text5.Text, Label12.Caption)
a = CENTUM1.PutTagData(Text6.Text, Label13.Caption)


Dim x As Integer
Sleep 1000 '1000 milliseconds

Loop Until Click



End Sub

Private Sub Stop_Click()
MSComm1.PortOpen = False
End Sub
Avatar billede lokespas Nybegynder
14. oktober 2003 - 11:48 #1
'du kunne jo skrive alt hvad der står i start_click ind i en function
'og som parameter kan du jo skrive den nye commando


Private Function SendCommand(sCommand As String)


MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True

Do
MSComm1.Output = sCommand + Chr$(13) + Chr$(10)
Avatar billede syncro Nybegynder
14. oktober 2003 - 12:01 #2
Jeg ville gerne have parameteren til at køre efter a = CENTUM1.PutTagData(Text6.Text, Label13.Caption)
Så den først kører den ene komando-læser og sender data og der efter den nye. Og man skal kun trykke på start en gang og den kører i loop på et sekund
Avatar billede lokespas Nybegynder
14. oktober 2003 - 12:19 #3
proev denne her kan desvaerre ikke teste den

MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True

Dim i As Integer
Dim sCommand(1) As String

sCommand(0) = "RC"
sCommand(1) = "RI"

i = 0

Do
MSComm1.Output = sCommand(i) + Chr$(13) + Chr$(10)

Do
dummy = DoEvents()
Loop Until MSComm1.InBufferCount >= 62

Label1.Caption = MSComm1.Input
Label2.Caption = Val(Mid$(Label1.Caption, 56, 8))
Label3.Caption = Val(Mid$(Label1.Caption, 48, 8))
Label4.Caption = Val(Mid$(Label1.Caption, 40, 8))
Label5.Caption = Val(Mid$(Label1.Caption, 28, 8))
Label6.Caption = Val(Mid$(Label1.Caption, 20, 8))
Label7.Caption = Val(Mid$(Label1.Caption, 10, 8))

Label8.Caption = (Label2.Caption * 0.1)
Label9.Caption = (Label3.Caption * 0.01)
Label10.Caption = (Label4.Caption * 0.001)
Label11.Caption = (Label5.Caption * 0.0001)
Label12.Caption = (Label6.Caption * 0.00001)
Label13.Caption = (Label7.Caption * 0.000001)



CENTUM1.StationName = "HIS0164"
a = CENTUM1.PutTagData(Text1.Text, Label8.Caption)
a = CENTUM1.PutTagData(Text2.Text, Label9.Caption)
a = CENTUM1.PutTagData(Text3.Text, Label10.Caption)
a = CENTUM1.PutTagData(Text4.Text, Label11.Caption)
a = CENTUM1.PutTagData(Text5.Text, Label12.Caption)
a = CENTUM1.PutTagData(Text6.Text, Label13.Caption)


Dim x As Integer
Sleep 1000 '1000 milliseconds

'naeste commando
If i = UBound(sCommand) Then
i = 0
Else
i = i + 1
End If

Loop Until Click
Avatar billede syncro Nybegynder
14. oktober 2003 - 14:11 #4
Det virker....men det jeg havde tænkt mig var bare en ny komando og en ny label

a = CENTUM1.PutTagData(Text5.Text, Label12.Caption)
a = CENTUM1.PutTagData(Text6.Text, Label13.Caption)

  Do
  MSComm1.Output = "RI" + Chr$(13) + Chr$(10)

  Do
  dummy = DoEvents()
  Loop Until MSComm1.InBufferCount >= 62
  Label14.Caption = MSComm1.Input



Dim x As Integer
Sleep 1000 '1000 milliseconds

Loop Until Click

Så man stadig har tallene fra den forgående og får et label med et nyt tal
Avatar billede lokespas Nybegynder
14. oktober 2003 - 14:52 #5
alså hvis det er "RC" skal input skrives til label1 og alle andre labels, hvis det er "RI" skal det skrives til label14 og kun label14 ??
Avatar billede syncro Nybegynder
14. oktober 2003 - 22:13 #6
Ja, og splittes op i label 15-17. Jeg kan bare ikke starte det
Avatar billede lokespas Nybegynder
15. oktober 2003 - 09:58 #7
MSComm1.CommPort = 1
MSComm1.Settings = "9600,N,8,1"
MSComm1.PortOpen = True

Dim i As Integer
Dim sCommand(1) As String

sCommand(0) = "RC"
sCommand(1) = "RI"

i = 0

Do
MSComm1.Output = sCommand(i) + Chr$(13) + Chr$(10)

Do
dummy = DoEvents()
Loop Until MSComm1.InBufferCount >= 62

If i = 0 Then
Label1.Caption = MSComm1.Input
Label2.Caption = Val(Mid$(Label1.Caption, 56, 8))
Label3.Caption = Val(Mid$(Label1.Caption, 48, 8))
Label4.Caption = Val(Mid$(Label1.Caption, 40, 8))
Label5.Caption = Val(Mid$(Label1.Caption, 28, 8))
Label6.Caption = Val(Mid$(Label1.Caption, 20, 8))
Label7.Caption = Val(Mid$(Label1.Caption, 10, 8))

Label8.Caption = (Label2.Caption * 0.1)
Label9.Caption = (Label3.Caption * 0.01)
Label10.Caption = (Label4.Caption * 0.001)
Label11.Caption = (Label5.Caption * 0.0001)
Label12.Caption = (Label6.Caption * 0.00001)
Label13.Caption = (Label7.Caption * 0.000001)



CENTUM1.StationName = "HIS0164"
a = CENTUM1.PutTagData(Text1.Text, Label8.Caption)
a = CENTUM1.PutTagData(Text2.Text, Label9.Caption)
a = CENTUM1.PutTagData(Text3.Text, Label10.Caption)
a = CENTUM1.PutTagData(Text4.Text, Label11.Caption)
a = CENTUM1.PutTagData(Text5.Text, Label12.Caption)
a = CENTUM1.PutTagData(Text6.Text, Label13.Caption)

Else

    Label14.Caption = MSComm1.Input
    'label 15 - 17
End If

Sleep 1000 '1000 milliseconds

'naeste commando
If i = UBound(sCommand) Then
    i = 0
Else
    i = 1
End If

Loop Until Click


jeg har fjernet Dim x As Integer
da jeg ikke ved hvad du vil bruge den til
Avatar billede syncro Nybegynder
16. oktober 2003 - 07:42 #8
Tak, det var lige det :-)

Kom med et svar.

Tak
Avatar billede lokespas Nybegynder
16. oktober 2003 - 09:12 #9
det var da herligt
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Kurser inden for grundlæggende programmering

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester