1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
| VERSION 5.00
Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX"
Object = "{BDC217C8-ED16-11CD-956C-0000C04E4C0A}#1.1#0"; "tabctl32.ocx"
Object = "{248DD890-BB45-11CF-9ABC-0080C7E7B78D}#1.0#0"; "MSWINSCK.OCX"
Dim ParamNum(0 To 5) As Integer
Dim EthernetConnected
Private WithEvents CommEvent As cComm242
Attribute CommEvent.VB_VarHelpID = -1
Private Sub Command1_Click()
End Sub
Private Sub cmdHelp_Click()
Dim MsgTxt As String
MsgTxt = "This program will help you understand communications with the EIES program." & vbCrLf
MsgTxt = MsgTxt & "Consult the communications section of the EIES User Guide for detailed information." & vbCrLf & vbCrLf
MsgTxt = MsgTxt & "First, setup your communications on the Utility tab." & vbCrLf & vbCrLf
MsgTxt = MsgTxt & "Select Query to read or Update to set values in the EIES program." & vbCrLf
MsgTxt = MsgTxt & "Select a parameter on the tabbed dialog. If Update is selected, enter a parameter value." & vbCrLf
MsgTxt = MsgTxt & "Press Send to send the Query or Update to the EIES program." & vbCrLf & vbCrLf
MsgTxt = MsgTxt & "The strings sent to and received from the EIES program are shown below."
MsgBox MsgTxt, , "EIES Comm Help"
End Sub
Private Sub CommEvent_ResponseEvent(sText As String)
Dim strData As String
strData = sText
Do While Len(strData) > 0
RcvMessage Left$(strData, 1)
strData = Right$(strData, Len(strData) - 1)
Loop
End Sub
Private Sub Form_Load()
Dim i As Integer
' In case SQS242 Comm not loaded
On Error Resume Next
Set CommEvent = SQS242Comm
Me.Caption = " " & Me.Caption & " - V" & App.Major & "." & App.Minor & App.Revision
For i = 0 To 99
cboLayer.AddItem i
Next i
cboOutput.Clear
cboPower.Clear
For i = 1 To 8
cboOutput.AddItem i
cboPower.AddItem i
Next i
cboPower.AddItem "All"
cboOutput.ListIndex = 0
cboPower.ListIndex = 0
cboLayer.ListIndex = 0
cboSensor.ListIndex = 0
cboOutputRdg.ListIndex = 0
cboSensorRdg.ListIndex = 0
optMode(0) = True
optQueryProcess(0) = True
optMeasure(10) = True
OptLayer(0) = True
optFilm(0) = True
optFilm(30) = True
optUtility(0) = True
optSensor(0) = True
tabMain.Tab = 0
' Read last comm setup (changed opt indexes, so a little remapping needed for backward compatibility)
cboPort.ListIndex = CInt(GetSetting(App.Title, "Comm Settings", "Port", "0"))
If cboPort.ListIndex < 0 Then cboPort.ListIndex = 0
cboBaud.ListIndex = CInt(GetSetting(App.Title, "Comm Settings", "Baud Rate", "0"))
If cboBaud.ListIndex < 0 Then cboBaud.ListIndex = 0
txtServer.Text = GetSetting(App.Title, "Comm Settings", "Ethernet Server", "")
txtPort.Text = GetSetting(App.Title, "Comm Settings", "Ethernet Port", "")
Select Case CInt(GetSetting(App.Title, "Comm Settings", "Comm Select", "3"))
Case 0, 1
'RS232
optComm(0).Value = True
Case 2
'Ethernet
optComm(2).Value = True
Case 3
'ActiveX
optComm(3).Value = True
End Select
End Sub
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Dim i As Integer
For i = 0 To 3
If i <> 1 Then
If optComm(i).Value = True Then
SaveSetting App.Title, "Comm Settings", "Comm Select", CStr(i)
Exit For
End If
End If
Next i
SaveSetting App.Title, "Comm Settings", "Port", cboPort.ListIndex
SaveSetting App.Title, "Comm Settings", "Baud Rate", cboBaud.ListIndex
SaveSetting App.Title, "Comm Settings", "Ethernet Server", txtServer
SaveSetting App.Title, "Comm Settings", "Ethernet Port", txtPort
If tcpMain.State = sckConnected Then
tcpMain.Close
End If
End Sub
Private Sub cmdSend_Click()
' Adds CRC and ships it out the comm or ethernet port
On Error Resume Next
Dim MsgString As String
If optMode(0) Then
Select Case tabMain.Tab
Case 0
MsgString = QueryProcess
Case 1 ' Process
MsgString = QueryMeasurement
Case 2
MsgString = QueryLayer
Case 3
MsgString = QueryFilm
Case 4
MsgString = QueryFilm
Case 5
MsgString = QuerySensor
Case 6
MsgString = QueryUtility
End Select
Else
Select Case tabMain.Tab
Case 0
MsgString = UpdateProcess
Case 1
'MsgString = UpdateMeasurement
Case 2
MsgString = UpdateLayer
Case 3
MsgString = UpdateFilm
Case 4
MsgString = UpdateFilm
Case 5
MsgString = UpdateSensor
Case 6
MsgString = UpdateUtility
End Select
End If
' Add the checksum to message and ship it
If chkChecksum.Value = vbChecked Then
MsgString = MsgString & ";" & CalcChkSum(MsgString & ";") & Chr$(13)
Else
MsgString = MsgString & ";" & "00" & Chr$(13)
End If
' Clear receive, and show transmit text boxes
If Len(MsgString) > 0 Then
txtSent = Left$(MsgString, Len(MsgString) - 1)
Else
txtSent = ""
End If
txtResponse = ""
' Ship it danno
Select Case True
Case optComm(0)
With MSComm1
.PortOpen = True
If .PortOpen Then
' Clear the receive buffer
.InBufferCount = 0
.Output = MsgString
' Set Tx Timeout timer
Else
' Trying to send with comm port closed
' Catch this case during development
Debug.Assert False
End If
End With
Case optComm(2)
' Ethernet selected, be sure we are connected
With tcpMain
If .State = sckConnected _
And .RemoteHost = txtServer _
And .RemotePort = CInt(Val(txtPort.Text)) Then
.SendData MsgString
Else
.Close
.LocalPort = 0
.RemoteHost = txtServer
.RemotePort = CInt(Val(txtPort.Text))
.Connect
TimeWait 1
.SendData MsgString
End If
End With
Case optComm(3)
SQS242Comm.Command = MsgString
End Select
End Sub
Private Sub RcvMessage(RcvChar As String)
Static MsgString As String
Dim NakErr As String
Select Case RcvChar
Case "@"
MsgString = RcvChar
Case Chr$(13)
Select Case Mid$(MsgString, 5, 1)
Case Chr$(6)
txtResponse = Left$(MsgString, 4) _
& "ACK" & Right$(MsgString, Len(MsgString) - 5)
Case Chr$(21)
Select Case Mid$(MsgString, 7, 2)
Case "01"
NakErr = "CMD"
Case "02"
NakErr = "PRM"
Case "03"
NakErr = "FMT"
Case "04"
NakErr = "CHK"
Case "05"
NakErr = "REQ"
Case "06"
NakErr = "UNK"
Case "07"
NakErr = "TMO"
End Select
txtResponse = Left$(MsgString, 4) _
& "NAK" & ";" & NakErr _
& Right$(MsgString, Len(MsgString) - 8)
Case Else
txtResponse = MsgString
End Select
Case Else
MsgString = MsgString & RcvChar
End Select
End Sub
Private Sub optSensor_Click(Index As Integer)
ParamNum(1) = Index + 1
End Sub
Private Sub tabMain_Click(PreviousTab As Integer)
Select Case tabMain.Tab
Case 1
optMode(0) = True
optMode(1).Enabled = False
Case Else
optMode(1).Enabled = True
End Select
End Sub
Private Sub tcpMain_DataArrival(ByVal bytesTotal As Long)
Dim strData As String
tcpMain.GetData strData
Do While Len(strData) > 0
RcvMessage Left$(strData, 1)
strData = Right$(strData, Len(strData) - 1)
Loop
End Sub
Private Sub MSComm1_OnComm()
With MSComm1
Select Case .CommEvent
Case comEvReceive
Do While .InBufferCount > 0
RcvMessage Chr$(AscB(.Input))
Loop
End Select
End With
End Sub
Private Sub cboBaud_Click()
MSComm1.Settings = cboBaud.Text & "n,8,1"
End Sub
Private Sub cboPort_Click()
If optComm(0) = True Then
MSComm1.CommPort = cboPort.ListIndex + 1
End If
End Sub
Private Sub optComm_Click(Index As Integer)
On Error Resume Next
Select Case Index
Case 0, 1
' Setup Comm port
With MSComm1
.CommPort = cboPort.ItemData(cboPort.ListIndex)
.Handshaking = comNone
.InBufferSize = 1024
.NullDiscard = False
.RTSEnable = False
.InputMode = comInputModeBinary
.InputLen = 1
.RThreshold = 1
.SThreshold = 0
End With
tcpMain.Close
Case 2
MSComm1.PortOpen = False
Case 3
MSComm1.PortOpen = False
tcpMain.Close
End Select
End Sub
Private Sub optFilm_Click(Index As Integer)
Select Case Index
Case Is < 6, 12 To 22
ParamNum(3) = Index + 1
Case Else
ParamNum(4) = Index + 1
End Select
End Sub
Private Sub optMeasure_Click(Index As Integer)
ParamNum(1) = Index + 1
End Sub
Private Sub optQueryProcess_Click(Index As Integer)
ParamNum(0) = Index + 1
End Sub
Private Sub optUtility_Click(Index As Integer)
ParamNum(5) = Index + 1
End Sub
Private Sub optUpdateProcess_Click(Index As Integer)
ParamNum(0) = Index + 1
End Sub
Private Sub optLayer_Click(Index As Integer)
ParamNum(2) = Index + 1
End Sub
Private Sub optMode_Click(Index As Integer)
Dim i As Integer
Select Case Index
Case 0
' Query Mode
optUpdateProcess(1).Enabled = False
optUpdateProcess(2).Enabled = False
optUpdateProcess(5).Enabled = False
optUpdateProcess(7).Enabled = False
optUpdateProcess(50).Enabled = False
optUpdateProcess(60).Enabled = False
For i = 1 To 7
optQueryProcess(i).Enabled = True
Next i
optQueryProcess(8).Enabled = True
optQueryProcess(10).Enabled = True
optQueryProcess(20).Enabled = True
' Measurements
Frame6.Enabled = True
'Layer
OptLayer(0).Enabled = True
OptLayer(1).Enabled = True
' Utility
For i = 10 To 12
optUtility(i).Enabled = True
Next i
txtUpdate.Visible = False
lblUpdate.Visible = False
Case 1
' Disable process inappropriate updates
optUpdateProcess(1).Enabled = True
optUpdateProcess(2).Enabled = True
optUpdateProcess(5).Enabled = True
optUpdateProcess(7).Enabled = True
optUpdateProcess(50).Enabled = True
optUpdateProcess(60).Enabled = True
For i = 1 To 7
optQueryProcess(i).Enabled = False
Next i
optQueryProcess(6).Enabled = True
optQueryProcess(8).Enabled = False
optQueryProcess(10).Enabled = False
optQueryProcess(20).Enabled = False
' Measurements
Frame6.Enabled = False
' Layer
OptLayer(0).Enabled = False
OptLayer(1).Enabled = False
'Utility
For i = 10 To 12
optUtility(i).Enabled = False
Next i
txtUpdate.Visible = True
lblUpdate.Visible = True
End Select
End Sub
Private Function CalcChkSum(ByRef Message As String) As String
' Calcultes the FCS checksum of a string of characters.
' Received messages must be stripped of their terminator charaters
' before passing to this routine.
Dim i As Integer
Dim FCS As Integer
' XOR ASCII codes
For i = 1 To Len(Message)
FCS = Asc(Mid$(Message, i, 1)) Xor FCS
Next i
' Conver to two character hex string
If Len(Hex$(FCS)) = 1 Then
CalcChkSum = "0" & Hex$(FCS)
Else
CalcChkSum = Hex$(FCS)
End If
End Function
Private Function QueryProcess() As String
Select Case ParamNum(0)
Case 1 To 10, 30 To 39, 71 To 74
QueryProcess = "@QP;0" & CStr(ParamNum(0))
Case 11 To 16
QueryProcess = "@QP;" & CStr(ParamNum(0) + cboPower.ListIndex)
Case 21 To 28
QueryProcess = "@QP;" & CStr(ParamNum(0) + cboPower.ListIndex)
Case 41 To 48
QueryProcess = "@QP;" & CStr(ParamNum(0) + cboPower.ListIndex)
End Select
End Function
Private Function UpdateProcess() As String
' Use Query as basis so only one routine is required
Select Case ParamNum(0)
Case 0 To 10, 36, 37, 38, 71 To 74
UpdateProcess = "@U" _
& Right$(QueryProcess, Len(QueryProcess) - 2) _
& ";" & txtUpdate
Case 11 ' Set Layer
UpdateProcess = "@UP;" & CStr(ParamNum(0)) & ";" & txtUpdate
Case 30
If txtUpdate = "1" Then
UpdateProcess = "@UP;31"
Else
UpdateProcess = "@UP;30"
End If
Case 32
If txtUpdate = "1" Then
UpdateProcess = "@UP;33"
Else
UpdateProcess = "@UP;32"
End If
Case 34
If txtUpdate = "1" Then
UpdateProcess = "@UP;35"
Else
UpdateProcess = "@UP;34"
End If
Case 41
UpdateProcess = "@UP;" & CStr(ParamNum(0) + CInt(cboPower.ListIndex)) & ";" & txtUpdate
Case 51
UpdateProcess = "@UP;" & CStr(ParamNum(0) + CInt(cboPower.ListIndex)) & ";" & txtUpdate
Case 61
UpdateProcess = "@UP;" & CStr(ParamNum(0) + CInt(cboPower.ListIndex)) & ";" & txtUpdate
End Select
End Function
Private Function QueryMeasurement() As String
Select Case ParamNum(1)
Case 1 To 2
Select Case cboSensorRdg.ListIndex
Case 0
' Emission current
QueryMeasurement = "@QM;5" & CStr(ParamNum(1))
Case 1
' Leakage Current
QueryMeasurement = "@QM;5" & CStr(ParamNum(1) + 4)
Case 2
' Power
QueryMeasurement = "@QM;6" & CStr(ParamNum(1))
Case 3
' Status
QueryMeasurement = "@QM;6" & CStr(ParamNum(1) + 4)
Case 4
' Filament Current
QueryMeasurement = "@QM;7" & CStr(ParamNum(1))
Case 5
' Bias voltage
QueryMeasurement = "@QM;7" & CStr(ParamNum(1) + 4)
End Select
Case 11 To 18
QueryMeasurement = "@QM;" & CStr((10 * cboOutputRdg.ListIndex) + ParamNum(1))
End Select
End Function
Private Function QueryLayer() As String
Select Case ParamNum(2)
Case 1
QueryLayer = "@QL;0" & CStr(ParamNum(2)) & ";" _
& (cboLayer.ListIndex) & ";" _
& (cboOutput.ListIndex)
Case 2
' Material is a film parameter, but clearer on this tab
QueryLayer = "@QF;0" & CStr(28) & ";" _
& (cboLayer.ListIndex) & ";" _
& (cboOutput.ListIndex)
Case 3 To 9
' Subtract one from paramnum because of material
QueryLayer = "@QL;0" & CStr(ParamNum(2) - 1) & ";" _
& (cboLayer.ListIndex) & ";" _
& (cboOutput.ListIndex)
Case 40, 42 To 46
QueryLayer = "@QL;" & CStr(ParamNum(2)) & ";" _
& (cboLayer.ListIndex) & ";" _
& (cboOutput.ListIndex)
Case 41
' Layer Index
Case 47
' Source Index Done
Case 48
'Layer Index Done
Case Else
QueryLayer = "@QL;" & CStr(ParamNum(2)) & ";" _
& (cboLayer.ListIndex) & ";" _
& (cboOutput.ListIndex)
End Select
End Function
Private Function UpdateLayer() As String
UpdateLayer = "@U" _
& Right$(QueryLayer, Len(QueryLayer) - 2) _
& ";" & txtUpdate
End Function
Private Function QueryFilm() As String
Select Case tabMain.Tab
Case 3
Select Case ParamNum(3)
Case 1 To 9
QueryFilm = "@QF;0" & CStr(ParamNum(3)) & ";" _
& (cboLayer.ListIndex) & ";" _
& (cboOutput.ListIndex)
Case 10 To 41
QueryFilm = "@QF;" & CStr(ParamNum(3)) & ";" _
& (cboLayer.ListIndex) & ";" _
& (cboOutput.ListIndex)
End Select
Case 4
Select Case ParamNum(4)
Case 1 To 9
QueryFilm = "@QF;0" & CStr(ParamNum(4)) & ";" _
& (cboLayer.ListIndex) & ";" _
& (cboOutput.ListIndex)
Case 10 To 41
QueryFilm = "@QF;" & CStr(ParamNum(4)) & ";" _
& (cboLayer.ListIndex) & ";" _
& (cboOutput.ListIndex)
End Select
End Select
End Function
Private Function UpdateFilm() As String
UpdateFilm = "@U" _
& Right$(QueryFilm, Len(QueryFilm) - 2) _
& ";" & txtUpdate
End Function
Private Function QueryUtility() As String
' This function requires an index because of the set Full Scale command
' so send a dummy index for 1 to 7, and 11 to 14
Select Case ParamNum(5)
Case 1 To 7, 11 To 14
QueryUtility = "@QU;0" & CStr(ParamNum(5))
Case 16
' Any string
QueryUtility = txtString
End Select
End Function
Private Function UpdateUtility() As String
Dim FPValue As Integer
Dim i As Integer
Select Case ParamNum(5)
Case 6
For i = 0 To 10
If chkFP(i).Value = vbChecked Then
FPValue = FPValue + (2 ^ i)
End If
Next i
UpdateUtility = "@U" _
& Right$(QueryUtility, Len(QueryUtility) - 2) _
& ";" & CStr(FPValue)
Case 1 To 5, 7, 11 To 14
UpdateUtility = "@U" _
& Right$(QueryUtility, Len(QueryUtility) - 2) _
& ";" & txtUpdate
End Select
End Function
Private Function QuerySensor() As String
Select Case cboSensor.ListIndex
Case 0
' Emission On/Off
QuerySensor = "@QS;0" & CStr((2 * (ParamNum(1) - 1)) + 1)
Case 1
' Emission SetPt
QuerySensor = "@QS;1" & CStr(ParamNum(1))
Case 2
' Max. leakage
QuerySensor = "@QS;2" & CStr(ParamNum(1))
Case 3
' Gas Cal
QuerySensor = "@QS;3" & CStr(ParamNum(1))
End Select
End Function
Private Function UpdateSensor() As String
Select Case cboSensor.ListIndex
Case 0
' Emission on/off
If txtUpdate = "1" Then
' On
UpdateSensor = "@US;0" & CStr(2 * ParamNum(1))
Else
' Off
UpdateSensor = "@US;0" & CStr((2 * ParamNum(1)) - 1)
End If
Case 1
' Emission Setpt
UpdateSensor = "@US;1" & CStr(ParamNum(1)) & ";" & txtUpdate
Case 2
' Max Leakage
UpdateSensor = "@US;2" & CStr(ParamNum(1)) & ";" & txtUpdate
Case 2
' Gas Cal
UpdateSensor = "@US;3" & CStr(ParamNum(1)) & ";" & txtUpdate
End Select
End Function
Public Sub TimeWait(ByVal nValue As Integer)
' Delay nValue seconds
Dim WaitTimer As Long
DoEvents
WaitTimer = Timer
Do While Timer - WaitTimer < nValue
If Timer < WaitTimer Then WaitTimer = Timer - WaitTimer + 86400
DoEvents
Loop
End Sub |
Partager