Capacity measurement

Jimys

New member
Joined
Mar 8, 2009
Messages
3
Programming Experience
Beginner
Hello, I found the code in vb5 (vb6) and I want to transfer it into the vb.net 2008. But I don't know how. See attachments. Could you help me?

Thanks
 

Attachments

  • capacitor_code.jpg
    capacitor_code.jpg
    28.7 KB · Views: 26
  • circuit_picture.jpg
    circuit_picture.jpg
    5.7 KB · Views: 26
I'm not sure what thats supposed to do, but it looks like it just opens a COM port and waits till it receives data? If thats all it does then you should be able to recreate it with ease with a SerialPort and Stopwatch.



I'm guessing by your thread title you want something more then that though, but not sure what.
 
I agree, but I don't know how to read analog signal on DSR port.

According to my understanding is the main issue to wait for signal on input. But there is no instruction like dsr.enabled=true in VB.net 2008. So how to create this part of code?


My title:
I found in old book this code and test circuit. You can measure roughly the capacity if you know that your resistor has 1000 Ohms. You have to measure the discharge pulse. 100ms = 100uF.

:) I have the better circuit with higher precision, but for beginning it is ok.
 
VB.NET:
   Public time As New Stopwatch

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        MessageBox.Show(SerialPort.GetPortNames().Length)
        Try
            SerialPort1.Open()
        Catch ex As Exception
            If SerialPort.GetPortNames().Length <= 0 Then
                MessageBox.Show("No ports were found.", "No ports to open.", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
            MessageBox.Show(ex.Message, "Couldn't open port.", MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub

    Sub Input(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived
        SerialPort1.DtrEnable = False
        time.Start()
        BackgroundWorker1.RunWorkerAsync()
    End Sub

    Sub WaitForSignal() Handles BackgroundWorker1.DoWork
        While SerialPort1.DsrHolding = True And time.ElapsedMilliseconds < 1501
            Thread.Sleep(100)
        End While
    End Sub
    Sub SignalFound() Handles BackgroundWorker1.RunWorkerCompleted
        time.Stop()
        Label1.Text = time.ElapsedMilliseconds.ToString
        SerialPort1.DtrEnable = True
    End Sub

This was my best guess at what you wanted. Not sure if I did it the best way. I couldn't test it but I think it will work.

Needs a Serial Port and a Background Worker placed.

Hope this helps.

Edit: Hmm. . . not sure if your allowed to access other objects properties from a different thread or not. I think you can, but I'm not sure. Anyway if it gives you an error tell me.
 
Last edited:
Thank you for your help. I had a problems with your code but it was big inspiration for me and I modified my code. I think that I have it.


Public time As New Stopwatch

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyTimer.Tick

time.Reset()
Myserial.Open()
Myserial.DtrEnable = True
time.Start()
While Myserial.DsrHolding = False And time.ElapsedMilliseconds < 2501

End While

time.Stop()
Label1.Text = time.ElapsedMilliseconds

Myserial.DtrEnable = False

Myserial.Close()

End Sub


I have to finish it. But the main idea is finished.
 
Back
Top