Pagina 2 di 6 primaprima 1 2 3 4 ... ultimoultimo
Visualizzazione dei risultati da 11 a 20 su 54
  1. #11
    Moderatore di Windows e software L'avatar di URANIO
    Registrato dal
    Dec 1999
    residenza
    Casalpusterlengo (LO)
    Messaggi
    1,288
    Stai convertendo un valore con la virgola,
    usa ad esempio
    Convert.ToDouble("100,00");

  2. #12
    Quote Originariamente inviata da optime Visualizza il messaggio
    posta il codice attuale


    Option Explicit On
    Imports System
    Imports System.IO
    Imports System.Net
    Imports System.Net.Sockets
    Imports System.Text
    Imports System.Threading




    Module Module1


    Function Right(ByVal value As String, ByVal length As Integer) As String
    ' Get rightmost characters of specified length.
    Return value.Substring(value.Length - length)
    End Function



    End Module




    Public Class Form1


    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


    End Sub




    Private oTCPStream As Net.Sockets.NetworkStream


    Private oTCP As New Net.Sockets.TcpClient()


    Private bytWriting As [Byte]() 'Private


    Private bytReading As Byte() 'Private


    Private oTCPStream_letture As Net.Sockets.NetworkStream


    Private oTCP_letture As New Net.Sockets.TcpClient()


    Public login As Integer
    Public luce1_accesa As Boolean
    Public pippo As Integer
    Public minni As Integer
    Public lettueLutron As String


    'Public subString() As String
    Public Gedeone As Integer


    Dim c As Integer
    Public hexVal As Integer
    Public percentuale As String
    Public varappoggio As String


    Public dato As Integer




    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click






    Try






    TextBox2.Text = ""


    oTCP.SendTimeout = 4500


    oTCP.Connect("192.168.1.100", "23")


    oTCPStream = oTCP.GetStream






    TextBox2.Text = TextBox2.Text & ReadData() & vbCrLf 'Reads data from server LUTRON and displays it in a textbox


    WriteData("FR041-Eni" & vbCrLf) 'Invio Login


    System.Threading.Thread.Sleep(100) 'Pausa'.


    TextBox2.Text = TextBox2.Text & ReadData() & vbCrLf 'Reads data from server LUTRON and displays it in a textbox






    WriteData("FR041-Eni" & vbCrLf) 'Reads data from server LUTRON and displays it in a textbox


    System.Threading.Thread.Sleep(100)
    TextBox2.Text = TextBox2.Text & ReadData() & vbCrLf






    BackgroundWorker1.RunWorkerAsync()




    Catch Err As Exception


    MsgBox(Err.ToString)


    End Try


    End Sub


    Private Sub BackgroundWorker1_DoWork(ByVal sender As System.Object, ByVal e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork


    re:

    Dim updateTxtBoxDel As UpdateTextBoxDelegate = New UpdateTextBoxDelegate(AddressOf UpdateTextBox)


    Me.Invoke(updateTxtBoxDel, ReadData() & vbCrLf) 'newTextValue
    '
    System.Threading.Thread.Sleep(1000)




    WriteData("?OUTPUT,101" & vbCrLf) 'Invio richiesta luci stato 1
    System.Threading.Thread.Sleep(100) 'Pausa'.


    varappoggio = ReadData()




    If varappoggio.Contains("~OUTPUT,101,1,100.00" & vbCrLf) Then '"OUTPUT,102,1,100.00"




    percentuale = varappoggio.Substring(13)
    hexVal = Convert.ToInt32(percentuale)
    dato = 1
    'Int32.TryParse(percentuale, hexVal)
    System.Threading.Thread.Sleep(1000) 'Pausa'.


    Else
    dato = 0


    End If




    System.Threading.Thread.Sleep(1000) 'Pausa'.


    GoTo re




    End Sub




    Delegate Sub UpdateTextBoxDelegate(ByVal myString As String)
    Delegate Sub UpdateTextBoxDelegate_1(ByVal myString_1 As String)


    Public Sub UpdateTextBox(ByVal myString As String)


    Me.TextBox9.Text = myString


    End Sub


    Public Sub UpdateTextBox_1(ByVal myString_1 As String)


    Me.TextBox11.Text = myString_1


    End Sub




    Private Sub WriteData(ByVal sData As String)


    bytWriting = System.Text.Encoding.ASCII.GetBytes(sData)


    oTCPStream.Write(bytWriting, 0, bytWriting.Length)


    End Sub




    Private Function ReadData() As String






    Dim sData As String


    ReDim bytReading(oTCP.ReceiveBufferSize)


    oTCPStream.Read(bytReading, 0, oTCP.ReceiveBufferSize)


    sData = Trim(System.Text.Encoding.ASCII.GetString(bytReadi ng))


    ReadData = sData




    End Function








    Private Sub RDim(ByVal bytReading As Byte)
    Throw New NotImplementedException
    End Sub






    Public Sub Timer10_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer10.Tick




    Dim ModbusClient As EasyModbus.ModbusClient = New EasyModbus.ModbusClient("10.0.0.10", "502") 'connecting using IP, port 'Dim
    Dim ComError = 0 'Dim




    Try






    ModbusClient.Connect()
    TextBox3.Text = ComError
    TextBox3.ForeColor = Color.Green
    Label4.Text = "Connected to Slave"
    Label4.ForeColor = Color.Green
    If TextBox3.Text = 0 Then
    Label4.Text = "logging......"
    Dim Regs As Integer()
    Regs = ModbusClient.ReadHoldingRegisters(0, 5)


    Me.TextBox4.Text = Regs(0)
    Me.TextBox5.Text = Regs(1)
    Me.TextBox6.Text = Regs(2)
    Me.TextBox7.Text = Regs(3)
    Me.TextBox8.Text = Regs(4)


    ModbusClient.WriteSingleRegister(19, c) 'Writes Holding Registro 19
    ModbusClient.WriteSingleRegister(20, hexVal)
    ModbusClient.WriteSingleRegister(21, minni)




    ModbusClient.Disconnect()


    End If




    Catch ex As Exception
    TextBox3.Text = 1
    TextBox3.ForeColor = Color.Red
    Label4.Text = "Connection Error!"
    Label4.ForeColor = Color.Red
    End Try
    End Sub


    End Class

  3. #13
    Ciao Uranio,

    grazie,

    da sempre errore....

  4. #14
    fermati col debug qui

    codice:
    hexVal = Convert.ToInt32(percentuale)


    e vedi cosa vale percentuale

  5. #15
    Ok, grazie, domani mattina proverò. Grazie.

    nel codice noti qualcosa che potrebbe dare noia?

    gtazie ancora

  6. #16
    Quote Originariamente inviata da ssormanni Visualizza il messaggio
    Ok, grazie, domani mattina proverò. Grazie.

    nel codice noti qualcosa che potrebbe dare noia?

    gtazie ancora

    Ho effettuato il debug, e la stringa ricevuta è la seguente:


    percentuale " ~OUTPUT,101,1,100.00 ~OUTPUT,101,29,8 ~OUTPUT,101,30,1,100.00 ~DEVICE,7,81,9,1 ~DEVICE,7,86,9,0 ~OUTPUT,101,1,100.00 QNET> " String

    da questa stringa che potrebbe anche variare, devo estrarre OUTPUT,101,1,100.00 e successivamente 100.00

    come potrei fare ?

    Come secondo step, dovrei fare la seguente cosa: Il valore che qua è indicato 100.00 in realtà è un valore che andare da 0.00 a 100.00 e lo dovrei salvare in un oggetto (intero)

    Grazie!!
    Ultima modifica di ssormanni; 12-11-2019 a 09:19

  7. #17
    prima cosa devi identificare bene il problema. devi estrarre "OUTPUT,101,1,100.00" come dici all'inizio o devi estrarre "OUTPUT,101,1,xxx.xx"
    dove xxx.xx può essere qualunque valore come dici successivamente?

  8. #18
    Quote Originariamente inviata da optime Visualizza il messaggio
    prima cosa devi identificare bene il problema. devi estrarre "OUTPUT,101,1,100.00" come dici all'inizio o devi estrarre "OUTPUT,101,1,xxx.xx"
    dove xxx.xx può essere qualunque valore come dici successivamente?

    La seconda, può essere un qualsiasi valore tra 0.00 e 100.00.

  9. #19
    quindi quale sarebbe la porzione di stringa che qualifica il valore da prelevare?

  10. #20
    OUTPUT,101,1,xxx.xx

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.