Demo Final
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -6,3 +6,4 @@
|
||||
/prjOnRampAPI/.vs/prjOnRampAPI
|
||||
/prjOnRampAPI/prjOnRampAPI/obj
|
||||
/prjOnRampAPI/obj
|
||||
/prjOnRampAPI/bin/Debug/net8.0
|
||||
|
||||
@@ -1,7 +1,162 @@
|
||||
Imports System
|
||||
|
||||
Imports System.Threading
|
||||
Imports ORPublicApiRefCore
|
||||
Imports ORSocketsCore
|
||||
Module Program
|
||||
|
||||
Private api As OnRampAPI
|
||||
Private socketClient As ORSocketClient
|
||||
Private quitEvent As ManualResetEvent = New ManualResetEvent(False)
|
||||
|
||||
|
||||
Sub Main(args As String())
|
||||
Console.WriteLine("Hello World!")
|
||||
|
||||
'The http_root endpoint - use the MAIN webserver, not a farm
|
||||
'Use ProdCopy for testing if needed
|
||||
Dim envUrl As String = "https://onramp.site.com/PROD"
|
||||
|
||||
|
||||
'create a socket connection to OnRamp Server to get interrupts of shop monitor events
|
||||
'You are registering as a "CLIENT APP NUMBER" - for this instance we will put SITE1001
|
||||
'SITE1001 is the ID you set in S1280 - Device Shop Monitor for the SOCKETID on the event you wish to capture on this application.
|
||||
socketClient = New ORSocketClient(envUrl, "SHOPMONITORCLIENT", "SITE1001")
|
||||
|
||||
'This is how to bind incoming Interrupt socket messages to a subroutine - kind of like a RS232 Interrupt
|
||||
AddHandler socketClient.OnMessageReceived, AddressOf SocketMessageRec
|
||||
|
||||
'This is so we can debug websocket debugging info (for info purposes only, socket connected, reconnected etc)
|
||||
AddHandler socketClient.OnLog, AddressOf SocketLog
|
||||
|
||||
|
||||
'Login to API to be able to query runQuery and Execute Queries in API Queries
|
||||
'You can do lots of things with the API like OpenScreens, change values - everything you can do with a dataloader you can do with the API
|
||||
api = New OnRampAPI(envUrl)
|
||||
|
||||
'Make an OnRamp user to use to login with the api and login with those credentials
|
||||
api.APILogin("api_user", "api_password")
|
||||
|
||||
'now the App waits forever and interrupts to SocketMessageRec
|
||||
WaitForConsoleExit()
|
||||
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub SocketMessageRec(obj As Object, e As ORSocketMessageReceivedArgs)
|
||||
'This is the interrupt when the "shop monitor event happens" - it acts like RS232 sort of.
|
||||
|
||||
Try
|
||||
'You get msg details like who sent it and when
|
||||
Dim senderGroup = e.senderGroup
|
||||
Dim senderName = e.senderName
|
||||
Dim msgTime = e.msgTime
|
||||
Dim msg = e.msg
|
||||
|
||||
'you get a message array
|
||||
Dim msgSplit() As String
|
||||
msgSplit = Split(msg, Convert.ToChar(175))
|
||||
|
||||
'msg = deviceid, channelNum, eventType
|
||||
|
||||
Dim deviceId As String = msgSplit(0)
|
||||
Dim channelNum As Integer = V_N2I(msgSplit(1))
|
||||
Dim eventType As ShopMonitorChannelEvent = V_N2I(msgSplit(2))
|
||||
|
||||
'you can tie into event types
|
||||
Select Case eventType
|
||||
Case ShopMonitorChannelEvent.WorkOrderLogin
|
||||
'new WO Logged in
|
||||
Case ShopMonitorChannelEvent.WorkOrderLogout
|
||||
'WO Logged out
|
||||
Case ShopMonitorChannelEvent.CycleStart
|
||||
'Cycle Start
|
||||
Case ShopMonitorChannelEvent.CycleDone
|
||||
'Cycle Done
|
||||
End Select
|
||||
|
||||
'^^With this information you can get all you want to know about the work order etc
|
||||
|
||||
'We create a query in S5011 - API Queries to get device_channel Work Order Info, then use other queries to get operation information etc
|
||||
'The queries in this example are just for example, you need to create your own.
|
||||
|
||||
'arguments for server query Q-1234
|
||||
Dim rsChannelArgs As New Dictionary(Of String, String)
|
||||
rsChannelArgs.Add("deviceid", deviceId)
|
||||
rsChannelArgs.Add("devicechannel", channelNum)
|
||||
|
||||
'Example Q-1234 query is
|
||||
'SELECT devc_cur_wo FROM device_chan WHERE devc_device_id = '{{p:deviceid}}' AND devc_channel_num = '{{p:devicechannel}}'
|
||||
Dim rstDataWo = api.runQuery("Q-1234", rsChannelArgs)
|
||||
|
||||
If rstDataWo.RecordCount > 0 Then
|
||||
Dim currentWoBarcode As String = rstDataWo("devc_cur_wo")
|
||||
|
||||
'get operation details
|
||||
Dim rsOperArgs As New Dictionary(Of String, String)
|
||||
rsOperArgs.Add("wobarcode", currentWoBarcode)
|
||||
|
||||
'Example Q-1235
|
||||
'SELECT wom_partnum, wom_nbr, woo_oper FROM wo_oper INNER JOIN wo_mstr ON wom_nbr = woo_nbr where woo_barcode = '{{p:wobarcode}}'
|
||||
Dim rstDataOp = api.runQuery("Q-1235", rsOperArgs)
|
||||
If rstDataOp.RecordCount > 0 Then
|
||||
Dim woNum As String = rstDataOp("wom_nbr")
|
||||
Dim woOp As Integer = V_N2I(rstDataOp("woo_oper"))
|
||||
Dim woPart As Integer = V_N2I(rstDataOp("wom_partnum"))
|
||||
|
||||
'get all operations for the WO
|
||||
Dim allOpsArgs As New Dictionary(Of String, String)
|
||||
allOpsArgs.Add("wonum", woNum)
|
||||
|
||||
'Example Q-1236
|
||||
'SELECT woo_oper, woo_qty_rep FROM wo_oper WHERE woo_nbr = '{{p:wonum}}'
|
||||
Dim rstDataAllOps = api.runQuery("Q-1236", allOpsArgs)
|
||||
If rstDataAllOps.RecordCount > 0 Then
|
||||
Do Until rstDataAllOps.EOF
|
||||
Console.WriteLine(rstDataAllOps("woo_oper") + " - QtyRep:" & rstDataAllOps("woo_qty_rep"))
|
||||
rstDataAllOps.MoveNext()
|
||||
Loop
|
||||
End If
|
||||
|
||||
'if we want to run an execute query
|
||||
Dim argUpdate As New Dictionary(Of String, String)
|
||||
argUpdate("deviceid") = deviceId
|
||||
argUpdate("part") = woPart
|
||||
|
||||
'Example Q-1237
|
||||
'UPDATE tbl_param_det SET PN = '{{p:part}}' WHERE Device = '{{p:deviceid}}'
|
||||
api.runQuery("Q-1237", argUpdate)
|
||||
|
||||
End If
|
||||
End If
|
||||
Catch ex As Exception
|
||||
Dim err As String = ex.Message
|
||||
End Try
|
||||
|
||||
End Sub
|
||||
|
||||
Private Sub SocketLog(obj As Object, msg As String)
|
||||
Console.WriteLine(msg)
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub WaitForConsoleExit()
|
||||
'console app wait forevery on main thread
|
||||
Console.WriteLine("Running. Press Ctrl+C to exit.")
|
||||
AddHandler Console.CancelKeyPress, AddressOf ConsoleCancel
|
||||
|
||||
|
||||
'Block here until Ctrl+C
|
||||
quitEvent.WaitOne()
|
||||
|
||||
Console.WriteLine("Shutting down...")
|
||||
Try
|
||||
socketClient?.Dispose()
|
||||
Catch
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
|
||||
Private Sub ConsoleCancel(sender, eArgs)
|
||||
quitEvent.[Set]()
|
||||
eArgs.Cancel = True
|
||||
End Sub
|
||||
|
||||
End Module
|
||||
|
||||
53
prjOnRampAPI/modOHCommon.vb
Normal file
53
prjOnRampAPI/modOHCommon.vb
Normal file
@@ -0,0 +1,53 @@
|
||||
Imports ORPublicApiRefCore
|
||||
|
||||
Public Module modOHCommon
|
||||
|
||||
|
||||
<ThreadStatic> Private _rstData As List(Of KeyValuePair(Of String, DTRecordSet))
|
||||
Public Property rs(ByVal uniqueIdent As String) As DTRecordSet
|
||||
Get
|
||||
Return rstData(uniqueIdent)
|
||||
End Get
|
||||
Set(value As DTRecordSet)
|
||||
rstData(uniqueIdent) = value
|
||||
End Set
|
||||
End Property
|
||||
Public Property rstData(ByVal uniqueIdent As String) As DTRecordSet
|
||||
Get
|
||||
Dim localRs As List(Of KeyValuePair(Of String, DTRecordSet))
|
||||
|
||||
If _rstData Is Nothing Then
|
||||
_rstData = New List(Of KeyValuePair(Of String, DTRecordSet))
|
||||
End If
|
||||
localRs = _rstData
|
||||
|
||||
For Each kvp As KeyValuePair(Of String, DTRecordSet) In localRs
|
||||
If kvp.Key = uniqueIdent Then
|
||||
Return kvp.Value
|
||||
End If
|
||||
Next kvp
|
||||
'Throw New Exception("rstData(" & uniqueIdent & ") could not be found")
|
||||
Return Nothing
|
||||
End Get
|
||||
Set(ByVal value As DTRecordSet)
|
||||
Dim localRs As List(Of KeyValuePair(Of String, DTRecordSet))
|
||||
|
||||
If _rstData Is Nothing Then
|
||||
_rstData = New List(Of KeyValuePair(Of String, DTRecordSet))
|
||||
End If
|
||||
localRs = _rstData
|
||||
|
||||
'remove from list if exists, then replace
|
||||
For Each kvp As KeyValuePair(Of String, DTRecordSet) In localRs
|
||||
If kvp.Key = uniqueIdent Then
|
||||
localRs.Remove(kvp)
|
||||
Exit For
|
||||
End If
|
||||
Next kvp
|
||||
Dim wrapKVP As New KeyValuePair(Of String, DTRecordSet)(uniqueIdent, value)
|
||||
localRs.Add(wrapKVP)
|
||||
End Set
|
||||
End Property
|
||||
|
||||
|
||||
End Module
|
||||
Reference in New Issue
Block a user