ex1.frm 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. VERSION 4.00
  2. Begin VB.Form Form1
  3. Caption = "Form1"
  4. ClientHeight = 6570
  5. ClientLeft = 1140
  6. ClientTop = 915
  7. ClientWidth = 8310
  8. Height = 6975
  9. Left = 1080
  10. LinkTopic = "Form1"
  11. ScaleHeight = 6570
  12. ScaleWidth = 8310
  13. Top = 570
  14. Width = 8430
  15. Begin VB.Timer Timer1
  16. Interval = 1000
  17. Left = 1080
  18. Top = 360
  19. End
  20. Begin VB.Frame inputregs
  21. Caption = "INPUT REGS"
  22. Height = 4575
  23. Left = 4320
  24. TabIndex = 8
  25. Top = 1440
  26. Width = 1695
  27. Begin VB.TextBox inregsaddress
  28. Height = 285
  29. Left = 480
  30. TabIndex = 9
  31. Text = "1"
  32. Top = 360
  33. Width = 735
  34. End
  35. Begin VB.Label inputreg
  36. Alignment = 2 'Center
  37. Caption = "0000"
  38. Height = 255
  39. Index = 9
  40. Left = 480
  41. TabIndex = 20
  42. Top = 4080
  43. Width = 735
  44. End
  45. Begin VB.Label inputreg
  46. Alignment = 2 'Center
  47. Caption = "0000"
  48. Height = 255
  49. Index = 8
  50. Left = 480
  51. TabIndex = 19
  52. Top = 3720
  53. Width = 735
  54. End
  55. Begin VB.Label inputreg
  56. Alignment = 2 'Center
  57. Caption = "0000"
  58. Height = 255
  59. Index = 7
  60. Left = 480
  61. TabIndex = 18
  62. Top = 3360
  63. Width = 735
  64. End
  65. Begin VB.Label inputreg
  66. Alignment = 2 'Center
  67. Caption = "0000"
  68. Height = 255
  69. Index = 6
  70. Left = 480
  71. TabIndex = 17
  72. Top = 3000
  73. Width = 735
  74. End
  75. Begin VB.Label inputreg
  76. Alignment = 2 'Center
  77. Caption = "0000"
  78. Height = 255
  79. Index = 5
  80. Left = 480
  81. TabIndex = 16
  82. Top = 2640
  83. Width = 735
  84. End
  85. Begin VB.Label inputreg
  86. Alignment = 2 'Center
  87. Caption = "0000"
  88. Height = 255
  89. Index = 4
  90. Left = 480
  91. TabIndex = 15
  92. Top = 2280
  93. Width = 735
  94. End
  95. Begin VB.Label inputreg
  96. Alignment = 2 'Center
  97. Caption = "0000"
  98. Height = 255
  99. Index = 3
  100. Left = 480
  101. TabIndex = 14
  102. Top = 1920
  103. Width = 735
  104. End
  105. Begin VB.Label inputreg
  106. Alignment = 2 'Center
  107. Caption = "0000"
  108. Height = 255
  109. Index = 2
  110. Left = 480
  111. TabIndex = 13
  112. Top = 1560
  113. Width = 735
  114. End
  115. Begin VB.Label inputreg
  116. Alignment = 2 'Center
  117. Caption = "0000"
  118. Height = 255
  119. Index = 1
  120. Left = 480
  121. TabIndex = 12
  122. Top = 1200
  123. Width = 735
  124. End
  125. Begin VB.Label inputreg
  126. Alignment = 2 'Center
  127. Caption = "0000"
  128. Height = 255
  129. Index = 0
  130. Left = 480
  131. TabIndex = 11
  132. Top = 840
  133. Width = 735
  134. End
  135. End
  136. Begin VB.Frame Frame4
  137. Caption = "HOLDING REGS"
  138. Height = 4575
  139. Left = 6360
  140. TabIndex = 4
  141. Top = 1440
  142. Width = 1455
  143. Begin VB.TextBox holdingregsaddress
  144. Height = 285
  145. Left = 360
  146. TabIndex = 7
  147. Text = "1"
  148. Top = 360
  149. Width = 855
  150. End
  151. Begin VB.Label holdingreg
  152. Alignment = 2 'Center
  153. Caption = "0000"
  154. Height = 255
  155. Index = 9
  156. Left = 360
  157. TabIndex = 29
  158. Top = 4080
  159. Width = 735
  160. End
  161. Begin VB.Label holdingreg
  162. Alignment = 2 'Center
  163. Caption = "0000"
  164. Height = 255
  165. Index = 8
  166. Left = 360
  167. TabIndex = 28
  168. Top = 3720
  169. Width = 735
  170. End
  171. Begin VB.Label holdingreg
  172. Alignment = 2 'Center
  173. Caption = "0000"
  174. Height = 255
  175. Index = 7
  176. Left = 360
  177. TabIndex = 27
  178. Top = 3360
  179. Width = 735
  180. End
  181. Begin VB.Label holdingreg
  182. Alignment = 2 'Center
  183. Caption = "0000"
  184. Height = 255
  185. Index = 6
  186. Left = 360
  187. TabIndex = 26
  188. Top = 3000
  189. Width = 735
  190. End
  191. Begin VB.Label holdingreg
  192. Alignment = 2 'Center
  193. Caption = "0000"
  194. Height = 255
  195. Index = 5
  196. Left = 360
  197. TabIndex = 25
  198. Top = 2640
  199. Width = 735
  200. End
  201. Begin VB.Label holdingreg
  202. Alignment = 2 'Center
  203. Caption = "0000"
  204. Height = 255
  205. Index = 4
  206. Left = 360
  207. TabIndex = 24
  208. Top = 2280
  209. Width = 735
  210. End
  211. Begin VB.Label holdingreg
  212. Alignment = 2 'Center
  213. Caption = "0000"
  214. Height = 255
  215. Index = 3
  216. Left = 360
  217. TabIndex = 23
  218. Top = 1920
  219. Width = 735
  220. End
  221. Begin VB.Label holdingreg
  222. Alignment = 2 'Center
  223. Caption = "0000"
  224. Height = 255
  225. Index = 2
  226. Left = 360
  227. TabIndex = 22
  228. Top = 1560
  229. Width = 735
  230. End
  231. Begin VB.Label holdingreg
  232. Alignment = 2 'Center
  233. Caption = "0000"
  234. Height = 255
  235. Index = 1
  236. Left = 360
  237. TabIndex = 21
  238. Top = 1200
  239. Width = 735
  240. End
  241. Begin VB.Label holdingreg
  242. Alignment = 2 'Center
  243. Caption = "0000"
  244. Height = 255
  245. Index = 0
  246. Left = 360
  247. TabIndex = 10
  248. Top = 840
  249. Width = 735
  250. End
  251. End
  252. Begin VB.Frame Frame2
  253. Caption = "COILS"
  254. Height = 4575
  255. Left = 2520
  256. TabIndex = 3
  257. Top = 1440
  258. Width = 1455
  259. Begin VB.CheckBox coilstatus
  260. Enabled = 0 'False
  261. Height = 255
  262. Index = 9
  263. Left = 600
  264. TabIndex = 50
  265. Top = 4080
  266. Width = 255
  267. End
  268. Begin VB.CheckBox coilstatus
  269. Enabled = 0 'False
  270. Height = 255
  271. Index = 8
  272. Left = 600
  273. TabIndex = 49
  274. Top = 3720
  275. Width = 255
  276. End
  277. Begin VB.CheckBox coilstatus
  278. Enabled = 0 'False
  279. Height = 255
  280. Index = 7
  281. Left = 600
  282. TabIndex = 48
  283. Top = 3360
  284. Width = 255
  285. End
  286. Begin VB.CheckBox coilstatus
  287. Enabled = 0 'False
  288. Height = 255
  289. Index = 6
  290. Left = 600
  291. TabIndex = 47
  292. Top = 3000
  293. Width = 255
  294. End
  295. Begin VB.CheckBox coilstatus
  296. Enabled = 0 'False
  297. Height = 255
  298. Index = 5
  299. Left = 600
  300. TabIndex = 46
  301. Top = 2640
  302. Width = 255
  303. End
  304. Begin VB.CheckBox coilstatus
  305. Enabled = 0 'False
  306. Height = 255
  307. Index = 4
  308. Left = 600
  309. TabIndex = 45
  310. Top = 2280
  311. Width = 255
  312. End
  313. Begin VB.CheckBox coilstatus
  314. Enabled = 0 'False
  315. Height = 255
  316. Index = 3
  317. Left = 600
  318. TabIndex = 44
  319. Top = 1920
  320. Width = 255
  321. End
  322. Begin VB.CheckBox coilstatus
  323. Enabled = 0 'False
  324. Height = 255
  325. Index = 2
  326. Left = 600
  327. TabIndex = 43
  328. Top = 1560
  329. Width = 255
  330. End
  331. Begin VB.CheckBox coilstatus
  332. Enabled = 0 'False
  333. Height = 255
  334. Index = 1
  335. Left = 600
  336. TabIndex = 42
  337. Top = 1200
  338. Width = 255
  339. End
  340. Begin VB.CheckBox coilstatus
  341. Enabled = 0 'False
  342. Height = 255
  343. Index = 0
  344. Left = 600
  345. TabIndex = 41
  346. Top = 840
  347. Width = 255
  348. End
  349. Begin VB.TextBox coiladdress
  350. Height = 285
  351. Left = 360
  352. TabIndex = 6
  353. Text = "1"
  354. Top = 360
  355. Width = 735
  356. End
  357. End
  358. Begin VB.Frame Frame1
  359. Caption = "INPUTS"
  360. Height = 4575
  361. Left = 600
  362. TabIndex = 2
  363. Top = 1440
  364. Width = 1575
  365. Begin VB.CheckBox inputstatus
  366. Enabled = 0 'False
  367. Height = 255
  368. Index = 9
  369. Left = 600
  370. TabIndex = 40
  371. Top = 4080
  372. Width = 255
  373. End
  374. Begin VB.CheckBox inputstatus
  375. Enabled = 0 'False
  376. Height = 255
  377. Index = 8
  378. Left = 600
  379. TabIndex = 39
  380. Top = 3720
  381. Width = 255
  382. End
  383. Begin VB.CheckBox inputstatus
  384. Enabled = 0 'False
  385. Height = 255
  386. Index = 7
  387. Left = 600
  388. TabIndex = 38
  389. Top = 3360
  390. Width = 255
  391. End
  392. Begin VB.CheckBox inputstatus
  393. Enabled = 0 'False
  394. Height = 255
  395. Index = 6
  396. Left = 600
  397. TabIndex = 37
  398. Top = 3000
  399. Width = 255
  400. End
  401. Begin VB.CheckBox inputstatus
  402. Enabled = 0 'False
  403. Height = 255
  404. Index = 5
  405. Left = 600
  406. TabIndex = 36
  407. Top = 2640
  408. Width = 255
  409. End
  410. Begin VB.CheckBox inputstatus
  411. Enabled = 0 'False
  412. Height = 255
  413. Index = 4
  414. Left = 600
  415. TabIndex = 35
  416. Top = 2280
  417. Width = 255
  418. End
  419. Begin VB.CheckBox inputstatus
  420. Enabled = 0 'False
  421. Height = 255
  422. Index = 3
  423. Left = 600
  424. TabIndex = 34
  425. Top = 1920
  426. Width = 255
  427. End
  428. Begin VB.CheckBox inputstatus
  429. Enabled = 0 'False
  430. Height = 255
  431. Index = 2
  432. Left = 600
  433. TabIndex = 33
  434. Top = 1560
  435. Width = 255
  436. End
  437. Begin VB.CheckBox inputstatus
  438. Enabled = 0 'False
  439. Height = 255
  440. Index = 1
  441. Left = 600
  442. TabIndex = 32
  443. Top = 1200
  444. Width = 255
  445. End
  446. Begin VB.CheckBox inputstatus
  447. Enabled = 0 'False
  448. Height = 255
  449. Index = 0
  450. Left = 600
  451. TabIndex = 31
  452. Top = 840
  453. Width = 255
  454. End
  455. Begin VB.TextBox inputaddress
  456. Height = 285
  457. Left = 360
  458. TabIndex = 5
  459. Text = "1"
  460. Top = 360
  461. Width = 735
  462. End
  463. End
  464. Begin VB.TextBox Device
  465. Height = 285
  466. Left = 3720
  467. TabIndex = 1
  468. Text = "1"
  469. Top = 720
  470. Width = 855
  471. End
  472. Begin VB.Label statusline
  473. Alignment = 2 'Center
  474. ForeColor = &H000000FF&
  475. Height = 255
  476. Left = 840
  477. TabIndex = 30
  478. Top = 1080
  479. Width = 6735
  480. End
  481. Begin VB.Label Label1
  482. Caption = "Device"
  483. BeginProperty Font
  484. name = "MS Sans Serif"
  485. charset = 0
  486. weight = 700
  487. size = 13.5
  488. underline = 0 'False
  489. italic = 0 'False
  490. strikethrough = 0 'False
  491. EndProperty
  492. Height = 375
  493. Left = 3600
  494. TabIndex = 0
  495. Top = 240
  496. Width = 1095
  497. End
  498. End
  499. Attribute VB_Name = "Form1"
  500. Attribute VB_Creatable = False
  501. Attribute VB_Exposed = False
  502. Public m_svr As IModSca
  503. Dim PollHandle(4) As Integer
  504. Dim status(4) As Integer
  505. Dim SlaveDevice As Integer
  506. Dim StartAddress(4) As Long
  507. Dim Modbus_Id(4) As Long
  508. Dim Counter As Integer
  509. Dim temp As Integer
  510. Dim Modbus_Addr As Long
  511. Private Sub Text4_Change()
  512. End Sub
  513. Private Sub coiladdress_Change()
  514. If (IsNumeric(coiladdress.Text)) Then
  515. StartAddress(1) = coiladdress.Text
  516. Modbus_Addr = Modbus_Id(1) + StartAddress(1)
  517. status(1) = m_svr.ModifyPollRequest(PollHandle(1), SlaveDevice, Modbus_Addr, 10)
  518. StatusMsg (status(1))
  519. End If
  520. End Sub
  521. Private Sub Device_Change()
  522. If (IsNumeric(Device.Text)) Then
  523. SlaveDevice = Device.Text
  524. Modbus_Addr = Modbus_Id(0) + StartAddress(0)
  525. temp = m_svr.ModifyPollRequest(PollHandle(0), SlaveDevice, Modbus_Addr, 10)
  526. Modbus_Addr = Modbus_Id(1) + StartAddress(1)
  527. temp = m_svr.ModifyPollRequest(PollHandle(1), SlaveDevice, Modbus_Addr, 10)
  528. Modbus_Addr = Modbus_Id(2) + StartAddress(2)
  529. temp = m_svr.ModifyPollRequest(PollHandle(2), SlaveDevice, Modbus_Addr, 10)
  530. Modbus_Addr = Modbus_Id(3) + StartAddress(3)
  531. temp = m_svr.ModifyPollRequest(PollHandle(3), SlaveDevice, Modbus_Addr, 10)
  532. End If
  533. End Sub
  534. Private Sub Form_Load()
  535. Set m_svr = CreateObject("ModScan32.Document")
  536. Modbus_Id(0) = 10000 'input status prefix
  537. Modbus_Id(1) = 0 'coil status prefix
  538. Modbus_Id(2) = 30000 'input register prefix
  539. Modbus_Id(3) = 40000 'holding register prefix
  540. SlaveDevice = 1
  541. For Counter = 0 To 3
  542. StartAddress(Counter) = 1
  543. Modbus_Addr = Modbus_Id(Counter) + StartAddress(Counter)
  544. PollHandle(Counter) = m_svr.CreatePollRequest(SlaveDevice, Modbus_Addr, 10)
  545. Next Counter
  546. statusline = "** UNINITIALIZED **"
  547. End Sub
  548. Private Sub Form_Terminate()
  549. For Counter = 0 To 4
  550. m_svr.DeletePollRequest (PollHandle(Counter))
  551. Next Counter
  552. End Sub
  553. Public Sub StatusMsg(Index As Integer)
  554. If Index = 0 Then statusline = ""
  555. If Index > 0 And Index < 256 Then statusline = "Slave Device Exception Response"
  556. If Index = 256 Then statusline = "Invalid Handle"
  557. If Index = 257 Then statusline = "Modbus Message Overrun"
  558. If Index = 258 Then statusline = "Invalid Address"
  559. If Index = 259 Then statusline = "Invalid Device Address"
  560. If Index = 260 Then statusline = "Invalid Length Specification"
  561. If Index = 261 Then statusline = "Invalid modbus command"
  562. If Index = 262 Then statusline = "Driver Out-Of-Memory"
  563. If Index = 263 Then statusline = "** Time-Out **"
  564. If Index = 264 Then statusline = "Invalid Protocol Specification"
  565. If Index = 265 Then statusline = "** Bad Checksum **"
  566. If Index = 266 Then statusline = "Server NOT Connected"
  567. If Index = 267 Then statusline = "Invalid Response from Driver"
  568. If Index = 268 Then statusline = "Modbus Write Failure"
  569. If Index = 269 Then statusline = "Remote Server not Connected"
  570. If Index = 270 Then statusline = "** UNINITIALIZED **"
  571. If Index = 271 Then statusline = "ModScan Demo Time Expired"
  572. End Sub
  573. Private Sub holdingregsaddress_Change()
  574. If (IsNumeric(holdingregsaddress.Text)) Then
  575. StartAddress(3) = holdingregsaddress.Text
  576. Modbus_Addr = Modbus_Id(3) + StartAddress(3)
  577. status(3) = m_svr.ModifyPollRequest(PollHandle(3), SlaveDevice, Modbus_Addr, 10)
  578. StatusMsg (status(3))
  579. End If
  580. End Sub
  581. Private Sub inputaddress_Change()
  582. If (IsNumeric(inputaddress.Text)) Then
  583. StartAddress(0) = inputaddress.Text
  584. Modbus_Addr = Modbus_Id(0) + StartAddress(0)
  585. status(0) = m_svr.ModifyPollRequest(PollHandle(0), SlaveDevice, Modbus_Addr, 10)
  586. StatusMsg (status(0))
  587. End If
  588. End Sub
  589. Private Sub inregsaddress_Change()
  590. If (IsNumeric(inregsaddress.Text)) Then
  591. StartAddress(2) = inregsaddress.Text
  592. Modbus_Addr = Modbus_Id(2) + StartAddress(2)
  593. status(2) = m_svr.ModifyPollRequest(PollHandle(2), SlaveDevice, Modbus_Addr, 10)
  594. StatusMsg (status(2))
  595. End If
  596. End Sub
  597. Private Sub Timer1_Timer()
  598. For Counter = 0 To 9
  599. status(0) = m_svr.ReadValue(PollHandle(0), Counter, temp)
  600. StatusMsg (status(0))
  601. If temp = 0 Then
  602. inputstatus(Counter).Value = 0
  603. Else
  604. inputstatus(Counter).Value = 1
  605. End If
  606. Next Counter
  607. For Counter = 0 To 9
  608. status(1) = m_svr.ReadValue(PollHandle(1), Counter, temp)
  609. StatusMsg (status(1))
  610. If temp = 0 Then
  611. coilstatus(Counter).Value = 0
  612. Else
  613. coilstatus(Counter).Value = 1
  614. End If
  615. Next Counter
  616. For Counter = 0 To 9
  617. status(2) = m_svr.ReadValue(PollHandle(2), Counter, temp)
  618. StatusMsg (status(2))
  619. inputreg(Counter).Caption = temp
  620. Next Counter
  621. For Counter = 0 To 9
  622. status(3) = m_svr.ReadValue(PollHandle(3), Counter, temp)
  623. StatusMsg (status(3))
  624. holdingreg(Counter).Caption = temp
  625. Next Counter
  626. End Sub