420 lines
15 KiB
VB.net
420 lines
15 KiB
VB.net
Imports System.IO
|
|
Imports TestOENcontrol.OpenControl.ERRMSG
|
|
|
|
Public Class Form1
|
|
|
|
Public TargetCN As String = ""
|
|
Public SourcePC As String = ""
|
|
|
|
#Region "ConnessioneCN"
|
|
Private Sub btnConnetti_Click(sender As System.Object, e As System.EventArgs) Handles btnConnetti.Click
|
|
' Connessione al CN
|
|
o_Connection(txtIndirizzoIP.Text)
|
|
' Verifica CN
|
|
Try
|
|
O_BootPhaseEnquiry(PhaseCN, errClass, errNum)
|
|
txtPhaseCN.Text = PhaseCN
|
|
Catch ex As Exception
|
|
MsgBox("Controllo non connesso !!!")
|
|
End Try
|
|
' Lettura processo CN
|
|
If PhaseCN = 4 Then
|
|
O_GetSelectedProcess(ProcessCN, errClass, errNum)
|
|
txtProcesso.Text = ProcessCN
|
|
' Verifica numero dischi logici
|
|
Dim Driveconn As Integer
|
|
o_GetNumDrive(Driveconn)
|
|
'
|
|
' Recupera nome dischi logici
|
|
Dim LogicName() As String = {}
|
|
O_GetNameDrive(Driveconn, LogicName)
|
|
'
|
|
cboDriveLogici.Items.Clear()
|
|
For i = 1 To Driveconn
|
|
If LogicName(i) <> "" Then
|
|
cboDriveLogici.Items.Add(LogicName(i))
|
|
End If
|
|
Next
|
|
cboDriveLogici.SelectedIndex = 0
|
|
Else
|
|
MsgBox(errClass & " " & errNum)
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
|
|
txtIndirizzoIP.Text = "192.168.0.1"
|
|
String.Format("###.###.###.###", txtIndirizzoIP.Text)
|
|
|
|
|
|
Dim Tree As New TreeNode("C:\Temp")
|
|
AddDirectory("C:\temp", Tree)
|
|
twPC.Nodes.Add(Tree)
|
|
Tree = Nothing
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
Private Sub AddDirectory(ByVal Name As String, ByRef Parent As TreeNode)
|
|
Dim Root As New IO.DirectoryInfo(Name)
|
|
Dim Par As TreeNode
|
|
|
|
For Each d As IO.DirectoryInfo In Root.GetDirectories()
|
|
Par = New TreeNode(d.Name)
|
|
AddDirectory(d.FullName, Par)
|
|
Parent.Nodes.Add(Par)
|
|
Par = Nothing
|
|
Next
|
|
|
|
For Each f As IO.FileInfo In Root.GetFiles
|
|
lwPC.Items.Add(f.Name)
|
|
Next
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "VariabiliDouble"
|
|
|
|
Private Sub btnLeggiVarDouble_Click(sender As System.Object, e As System.EventArgs) Handles btnLeggiVarDouble.Click
|
|
' Lettura variabile double
|
|
Dim nTypeMem As UShort = 41
|
|
Dim nNumVar As UShort = 1
|
|
Dim nIndex As UShort = 1
|
|
Dim sValue() As Double = {}
|
|
nNumVar = CUShort(txtVarDoubleUsed.Text)
|
|
O_ReadVarDouble(nTypeMem, ProcessCN, nIndex, nNumVar, sValue, errClass, errNum)
|
|
txtVarDoubleRead.Text = sValue(nNumVar - 1)
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
End Sub
|
|
|
|
Private Sub btnScriviVarDouble_Click(sender As System.Object, e As System.EventArgs) Handles btnScriviVarDouble.Click
|
|
' Scrittuta variabile double
|
|
Dim nTypeMem As UShort = 41
|
|
Dim nNumVar As Integer = 1
|
|
Dim nIndex As UShort = 1
|
|
nNumVar = (txtVarDoubleUsed.Text)
|
|
Dim sValue(nNumVar - 1) As Double
|
|
sValue(nNumVar - 1) = CDbl(txtVarDoubleWrite.Text)
|
|
O_WriteVarDouble(nTypeMem, ProcessCN, nIndex, nNumVar, sValue, errClass, errNum)
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "VariabiliBoolean"
|
|
|
|
Private Sub btnScriviVarBool_Click(sender As System.Object, e As System.EventArgs) Handles btnScriviVarBool.Click
|
|
' Scrittura varibili Boolean
|
|
Dim nLen As Integer
|
|
nLen = InStr(txtVariabileBool.Text, ".")
|
|
Dim nNumVar As UShort = 1
|
|
Dim nTypeMem As UShort = 21
|
|
Dim nIndex As UShort = Val(Mid(txtVariabileBool.Text, 1, nLen)) ' 102
|
|
Dim nBitIndex As UShort = Val(Mid(txtVariabileBool.Text, nLen + 1)) '.1
|
|
Dim nBitValue As UShort = Val(txtVariabileBoolScritta.Text)
|
|
O_WriteVarWordBit(nTypeMem, ProcessCN, nIndex, nBitIndex, nBitValue, errClass, errNum)
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
End Sub
|
|
|
|
Private Sub btnLeggiVarBool_Click(sender As System.Object, e As System.EventArgs) Handles btnLeggiVarBool.Click
|
|
' Lettura varibili Boolean
|
|
Dim nLen As Integer
|
|
nLen = InStr(txtVariabileBool.Text, ".")
|
|
Dim nTypeMem As UShort = 21
|
|
Dim nIndex As UShort = Val(Mid(txtVariabileBool.Text, 1, nLen)) ' 102
|
|
Dim nBitIndex As UShort = Val(Mid(txtVariabileBool.Text, nLen + 1)) '.1
|
|
Dim nBitValue As UShort = 1
|
|
O_ReadVarWordBit(nTypeMem, ProcessCN, nIndex, nBitIndex, nBitValue, errClass, errNum)
|
|
txtVariabileBoolLetta.Text = nBitValue
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "VariabiliShort"
|
|
|
|
Private Sub btnReadVariabile_Click(sender As System.Object, e As System.EventArgs) Handles btnReadVariabile.Click
|
|
' Lettura variabili short
|
|
Dim nTypeMem As UShort = 21
|
|
Dim nNumVar As UShort = 1
|
|
Dim nIndex As UShort = 1
|
|
Dim sValue() As UShort = {}
|
|
nNumVar = CUShort(txtVariabileShort.Text)
|
|
O_ReadVarWord(nTypeMem, ProcessCN, nNumVar, nIndex, sValue, errClass, errNum)
|
|
Dim ValCorr As Short = UShortToShort(sValue(0))
|
|
txtResultShort.Text = ValCorr
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
End Sub
|
|
|
|
Private Sub btnWriteVariabile_Click(sender As System.Object, e As System.EventArgs) Handles btnWriteVariabile.Click
|
|
' Scrittura variabile short
|
|
Dim nTypeMem As UShort = 21
|
|
Dim nIndex As Short = 1
|
|
Dim nNumVar As UShort
|
|
Dim sValue() As UShort
|
|
Dim ValShort As Short
|
|
nNumVar = CUShort(txtVariabileShort.Text)
|
|
ReDim sValue(nNumVar - 1)
|
|
ValShort = (txtSendShort.Text)
|
|
sValue(nNumVar - 1) = ShortToUShort(ValShort)
|
|
O_WriteVarWord(nTypeMem, ProcessCN, nIndex, nNumVar, sValue, errClass, errNum)
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "VariabiliTesto"
|
|
|
|
Private Sub btnLeggiVariabileTesto_Click(sender As System.Object, e As System.EventArgs) Handles btnLeggiVariabileTesto.Click
|
|
' Lettura varibile testo SC
|
|
Dim nTypeMem As UShort = 50
|
|
Dim nStartVar As Integer = Val(txtStartLettura.Text)
|
|
Dim nVariabile As Integer = 100 ' Len(txtValoreScrivere.Text)
|
|
Dim szText As String = ""
|
|
O_ReadVarText(nTypeMem, ProcessCN, nStartVar, nVariabile, szText, errClass, errNum)
|
|
txtValoreLetto.Text = Replace(szText, " ", "")
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
End Sub
|
|
|
|
Private Sub btnScriviVariabileTesto_Click(sender As System.Object, e As System.EventArgs) Handles btnScriviVariabileTesto.Click
|
|
' Scrittura variabile testo SC
|
|
Dim nTypeMem As UShort = 50
|
|
Dim nStartVar As Integer = Val(txtStartLettura.Text)
|
|
Dim nVariabile As Integer
|
|
Dim szText As String = ""
|
|
szText = New String(" ", 100)
|
|
nVariabile = 100
|
|
O_WriteVarText(nTypeMem, ProcessCN, nStartVar, nVariabile, szText, errClass, errNum)
|
|
nVariabile = Len(txtValoreScrivere.Text)
|
|
szText = txtValoreScrivere.Text
|
|
O_WriteVarText(nTypeMem, ProcessCN, nStartVar, nVariabile, szText, errClass, errNum)
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "VariabileE"
|
|
|
|
Private Sub btnReadVarE_Click(sender As System.Object, e As System.EventArgs) Handles btnReadVarE.Click
|
|
' Lettura variabile E
|
|
Dim nTypeMem As UShort = 46
|
|
Dim nNumVar As UShort = 1
|
|
Dim nIndex As UShort = 1
|
|
Dim sValue() As Double = {}
|
|
nIndex = CDbl(txtVarE.Text)
|
|
O_ReadVarDouble(nTypeMem, ProcessCN, nIndex, nNumVar, sValue, errClass, errNum)
|
|
txtVarERead.Text = sValue(0)
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
End Sub
|
|
|
|
Private Sub btnWriteVarE_Click(sender As System.Object, e As System.EventArgs) Handles btnWriteVarE.Click
|
|
' Scrittuta variabile E
|
|
Dim nTypeMem As UShort = 46
|
|
Dim nNumVar As Integer = 1
|
|
Dim nIndex As UShort = 0
|
|
nIndex = txtVarE.Text
|
|
Dim sValue(nNumVar - 1) As Double
|
|
sValue(0) = CDbl(txtVarESend.Text)
|
|
O_WriteVarDouble(nTypeMem, ProcessCN, nIndex, nNumVar, sValue, errClass, errNum)
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "VariabiliSN"
|
|
|
|
Private Sub btnReadSN_Click(sender As System.Object, e As System.EventArgs) Handles btnReadSN.Click
|
|
' Lettura variabile SN
|
|
Dim nTypeMem As UShort = 47
|
|
Dim nNumVar As UShort = 1
|
|
Dim nIndex As UShort = 1
|
|
Dim sValue() As Double = {}
|
|
nIndex = CDbl(txtVariabileSN.Text)
|
|
O_ReadVarDouble(nTypeMem, ProcessCN, nIndex, nNumVar, sValue, errClass, errNum)
|
|
txtVariabileSNRead.Text = sValue(0)
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
End Sub
|
|
|
|
Private Sub btnWriteSN_Click(sender As System.Object, e As System.EventArgs) Handles btnWriteSN.Click
|
|
' Scrittuta variabile SN
|
|
Dim nTypeMem As UShort = 47
|
|
Dim nNumVar As Integer = 1
|
|
Dim nIndex As UShort = 0
|
|
nIndex = txtVariabileSN.Text
|
|
Dim sValue(nNumVar - 1) As Double
|
|
sValue(0) = CDbl(txtVariabileSNWrite.Text)
|
|
O_WriteVarDouble(nTypeMem, ProcessCN, nIndex, nNumVar, sValue, errClass, errNum)
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
#Region "GestioneFile"
|
|
|
|
Private Sub cboDriveLogici_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboDriveLogici.SelectedIndexChanged
|
|
' Legge directory e file nel drive selezionato
|
|
Dim Nome As String
|
|
Dim ListDir() As String = {}
|
|
Dim ListFile() As String = {}
|
|
lwDirCN.Items.Clear()
|
|
lwFileCN.Items.Clear()
|
|
Nome = cboDriveLogici.SelectedItem
|
|
o_FindDirFile(Nome, ListDir, ListFile)
|
|
Dim NumeroDir As Integer = UBound(ListDir)
|
|
Dim Numerofile As Integer = UBound(ListFile)
|
|
For i = 1 To NumeroDir
|
|
lwDirCN.Items.Add(ListDir(i), 1)
|
|
Next
|
|
For i = 1 To Numerofile
|
|
lwFileCN.Items.Add(ListFile(i), 1)
|
|
Next
|
|
End Sub
|
|
|
|
Private Sub lwDirCN_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles lwDirCN.SelectedIndexChanged
|
|
' Legge directory e file nel drive selezionato
|
|
Dim NomeDrive As String = ""
|
|
Dim NomeDir As String = ""
|
|
Dim NomeCompleto
|
|
NomeDrive = cboDriveLogici.SelectedItem
|
|
For Each ob As Object In lwDirCN.SelectedItems
|
|
NomeDir = ob.text
|
|
Next
|
|
Dim ListDir() As String = {}
|
|
Dim ListFile() As String = {}
|
|
lwDirCN.Items.Clear()
|
|
lwFileCN.Items.Clear()
|
|
NomeCompleto = NomeDrive & "\\" & NomeDir
|
|
o_FindDirFile(NomeCompleto, ListDir, ListFile)
|
|
Dim NumeroDir As Integer = UBound(ListDir)
|
|
Dim Numerofile As Integer = UBound(ListFile)
|
|
For i = 1 To NumeroDir
|
|
lwDirCN.Items.Add(ListDir(i), 1)
|
|
Next
|
|
For i = 1 To Numerofile
|
|
lwFileCN.Items.Add(ListFile(i), 1)
|
|
Next
|
|
TargetCN = NomeCompleto
|
|
End Sub
|
|
|
|
Private Sub twPC_AfterSelect(sender As System.Object, e As System.Windows.Forms.TreeViewEventArgs) Handles twPC.AfterSelect
|
|
' Seelziona directory
|
|
Dim Percorso As String
|
|
Percorso = twPC.SelectedNode.FullPath
|
|
lwPC.Items.Clear()
|
|
Dim files() As String = Directory.GetFiles(Percorso)
|
|
Dim fi As FileInfo
|
|
Dim lvi As ListViewItem
|
|
'
|
|
SourcePC = Percorso
|
|
For i = 0 To files.Length - 1
|
|
'
|
|
fi = New FileInfo(files(i))
|
|
lvi = New ListViewItem(Path.GetFileName(files(i)), 1)
|
|
lvi.SubItems.Add(fi.Length)
|
|
lvi.SubItems.Add(fi.LastAccessTime)
|
|
'
|
|
lwPC.Items.Add(lvi)
|
|
'
|
|
Next
|
|
End Sub
|
|
|
|
Private Sub lwPC_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles lwPC.SelectedIndexChanged
|
|
Dim FileToSend As String = ""
|
|
Dim FileSize As Integer
|
|
For Each ob As Object In lwPC.SelectedItems
|
|
FileToSend = ob.text
|
|
FileSize = My.Computer.FileSystem.GetFileInfo(SourcePC & "\" & ob.text).Length
|
|
|
|
Console.WriteLine(FileToSend)
|
|
O_PutFile(SourcePC & "\" & FileToSend, TargetCN & "\\" & FileToSend, errClass, errNum, FileSize)
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
Next
|
|
End Sub
|
|
|
|
#End Region
|
|
|
|
Private Sub lwFileCN_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles lwFileCN.SelectedIndexChanged
|
|
Dim FileToGet As String = ""
|
|
For Each ob As Object In lwFileCN.SelectedItems
|
|
FileToGet = ob.text
|
|
Console.WriteLine(FileToGet)
|
|
O_GetBinaryFile(TargetCN & "\\" & FileToGet, SourcePC & "\" & FileToGet, errClass, errNum)
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
Next
|
|
End Sub
|
|
|
|
Private Sub btnLeggiMsgErr_Click(sender As System.Object, e As System.EventArgs) Handles btnLeggiMsgPrg.Click
|
|
Dim MessaggioDis As String = ""
|
|
O_ReadPartProgramMsg(txtProcesso.Text, MessaggioDis, errClass, errNum)
|
|
txtMessaggioDis.Text = MessaggioDis
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
End Sub
|
|
|
|
|
|
Private Sub btnMessaggioerrore_Click(sender As System.Object, e As System.EventArgs) Handles btnMessaggioerrore.Click
|
|
|
|
Dim MessaggioErr() As String = {}
|
|
|
|
O_ReadCurrentErrorMsg(txtProcesso.Text, MessaggioErr, errClass, errNum)
|
|
|
|
Try
|
|
txtMessErr01.Text = MessaggioErr(1)
|
|
txtMessErr02.Text = MessaggioErr(2)
|
|
txtMessErr03.Text = MessaggioErr(3)
|
|
txtMessErr04.Text = MessaggioErr(4)
|
|
Catch ex As Exception
|
|
|
|
End Try
|
|
|
|
|
|
' txtMessaggioDis.Text = MessaggioErr
|
|
Console.WriteLine(errClass & " " & errNum)
|
|
|
|
End Sub
|
|
|
|
|
|
Private Sub btnReadActivePrg_Click(sender As System.Object, e As System.EventArgs) Handles btnReadActivePrg.Click
|
|
|
|
Dim PrgActive As String = ""
|
|
|
|
O_ActiveProgram(txtProcesso.Text, PrgActive, errClass, errNum)
|
|
txtProgrammaAttivo.Text = PrgActive
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
|
|
Private Sub btnActivePrg_Click(sender As System.Object, e As System.EventArgs) Handles btnActivePrg.Click
|
|
Dim PrgToActive As String = ""
|
|
For Each ob As Object In lwFileCN.SelectedItems
|
|
PrgToActive = ob.text
|
|
Next
|
|
PrgToActive = TargetCN & "\\" & PrgToActive
|
|
O_SelectPartProgram(txtProcesso.Text, PrgToActive, errClass, errNum)
|
|
End Sub
|
|
|
|
|
|
Private Sub btnErrMess_Click(sender As System.Object, e As System.EventArgs) Handles btnErrMess.Click
|
|
Dim MessaggioErr() As String = {}
|
|
|
|
O_ReadMessage(txtProcesso.Text, MessaggioErr, errClass, errNum)
|
|
|
|
End Sub
|
|
|
|
|
|
Private Sub btnPLCAlarm_Click(sender As System.Object, e As System.EventArgs) Handles btnPLCAlarm.Click
|
|
|
|
Dim ErrMsgPLC As String = ""
|
|
|
|
O_ReadWarningMessage(txtProcesso.Text, ErrMsgPLC, errClass, errNum)
|
|
|
|
End Sub
|
|
|
|
|
|
|
|
Private Sub txtVarERead_TextChanged(sender As System.Object, e As System.EventArgs) Handles txtVarERead.TextChanged
|
|
|
|
End Sub
|
|
End Class
|