|
currrently my thermistor is able to capture temperature however after i click on checkbox1 it display Conversion from string "" to type 'Integer' is not valid please advise thanks
Imports System.Speech.Synthesis
Public Class Form1
Dim FromSerialPort1 As String
Dim XX(100) As Integer
Dim YY(100) As Integer
Dim ZZ(100) As Integer
Dim Flag As Integer
Dim Speaker_Flag As Integer = 0
Dim FromSerialPort_Temp
Dim Thermistor_Temp(15) As Integer
Dim Thermistor_R(15) As Integer
Dim Circuit_Thermistor_R As Double
Dim Result
Dim Counter As Integer
Dim Temperature_low
Dim Temperature_high
Dim Resistance_low
Dim Resistance_high
Dim Rnum1
Dim Rnum2
Dim Speaker As New SpeechSynthesizer
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
TimerSpeak2.Enabled = True
TimerTemp.Enabled = True
Private Sub ReadSerialPortForTemp()
FromSerialPort_Temp = SerialPortTemp.ReadExisting
If Len(FromSerialPort_Temp) <> 0 Then
TextBoxVoltage.Text = 0.01 * Convert.ToInt16(FromSerialPort_Temp.SubString(2, 3), 16)
Else
FromSerialPort_Temp = "U1000"
End If
End Sub
Private Sub OpenPort1()
If SerialPortTemp.IsOpen Then
SerialPortTemp.Close()
End If
SerialPortTemp.PortName = "Com4"
SerialPortTemp.BaudRate = 9600
SerialPortTemp.Parity = System.IO.Ports.Parity.None
SerialPortTemp.DataBits = 8
SerialPortTemp.StopBits = System.IO.Ports.StopBits.One
SerialPortTemp.RtsEnable = True
SerialPortTemp.Open()
End Sub
Private Sub ThermistorTable()
Thermistor_Temp(0) = -10
Thermistor_R(0) = 42506
Thermistor_Temp(1) = -5
Thermistor_R(1) = 33892
Thermistor_Temp(2) = 0
Thermistor_R(2) = 27219
Thermistor_Temp(3) = 5
Thermistor_R(3) = 22021
Thermistor_Temp(4) = 10
Thermistor_R(4) = 17926
Thermistor_Temp(5) = 15
Thermistor_R(5) = 14674
Thermistor_Temp(6) = 20
Thermistor_R(6) = 12081
Thermistor_Temp(7) = 25
Thermistor_R(7) = 10000
Thermistor_Temp(8) = 30
Thermistor_R(8) = 8315
Thermistor_Temp(9) = 35
Thermistor_R(9) = 6948
Thermistor_Temp(10) = 40
Thermistor_R(10) = 5834
Thermistor_Temp(11) = 45
Thermistor_R(11) = 4917
Thermistor_Temp(12) = 50
Thermistor_R(12) = 4161
Thermistor_Temp(13) = 55
Thermistor_R(13) = 3535
Thermistor_Temp(14) = 60
Thermistor_R(14) = 3014
Thermistor_Temp(15) = 1000
Thermistor_R(15) = 1
For Counter = 0 To 15
If CInt(TextBoxResistance.Text) >= Thermistor_R(Counter) Then
If Counter <> 0 And Counter <> 15 Then
Temperature_high = Thermistor_Temp(Counter)
Temperature_low = Thermistor_Temp(Counter - 1)
Resistance_low = Thermistor_R(Counter)
Resistance_high = Thermistor_R(Counter - 1)
Rnum1 = Resistance_high - TextBoxResistance.Text
Rnum2 = Resistance_high - Resistance_low
Result = 2.5 + Math.Round(Temperature_low + (5 * Rnum1 / Rnum2), 1)
TextBoxTemp.Text = Result & "C"
Exit For
If Counter = 0 Or Counter = 15 Then
TextBoxTemp.Text = "Out Of Range"
Exit For
End If
End If
End If
Next
End Sub
Private Sub TimerTemp_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerTemp.Tick
Call OpenPort1()
TextBoxVoltage.Clear()
TextBoxResistance.Clear()
TextBoxTemp.Clear()
SerialPortTemp.WriteLine("U1" + vbCr)
System.Threading.Thread.Sleep(150)
Call ReadSerialPortForTemp()
If Len(TextBoxVoltage.Text) = 0 Then
Else
Circuit_Thermistor_R = 10000 * TextBoxVoltage.Text / (5 - TextBoxVoltage.Text)
TextBoxResistance.Text = Math.Round(Circuit_Thermistor_R, 0)
Call ThermistorTable()
End If
End Sub
Private Sub TimerSpeak2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TimerSpeak2.Tick
Call ThermistorTable()
If CheckBox1.Checked = True Then //from this part
Call ThermistorTable()
If Result >= 0 Then
TextBox.Text = ""
TextBox.Text = "Your Temperature is" + "" + TextBoxTemp.Text
TextBox.Refresh()
Speaker.Speak(TextBox.Text)
End If //to this part
|
|
|
|
|
Though I do not usually do this, I have spent five minutes to parse your code snippet correctly. What I can see is that Thermistor_Temp and Thermistor_R arrays have always the same values, so you should better initialize them just once in the constructor, becouse you are now initializing them with the same values every time you call ThermistorTable.
In this loop in ThermistorTable method:
For Counter = 0 To 15
If CInt(TextBoxResistance.Text) >= Thermistor_R(Counter) Then
If Counter <> 0 And Counter <> 15 Then
Temperature_high = Thermistor_Temp(Counter)
Temperature_low = Thermistor_Temp(Counter - 1)
Resistance_low = Thermistor_R(Counter)
Resistance_high = Thermistor_R(Counter - 1)
Rnum1 = Resistance_high - TextBoxResistance.Text
Rnum2 = Resistance_high - Resistance_low
Result = 2.5 + Math.Round(Temperature_low + (5 * Rnum1 / Rnum2), 1)
TextBoxTemp.Text = Result & "C"
Exit For
If Counter = 0 Or Counter = 15 Then
TextBoxTemp.Text = "Out Of Range"
Exit For
End If
End If
End If
Next
I guess you are looking for the first value on your array which is lesser or equal to what you have in TextBoxResistance. Not too bad, but somewhat confusing, and the last if will never run. I would have done it this way:
Dim r As Integer = CInt(TextBoxResistance.Text)
Dim idx As Integer = 0
While r < Thermistor_R(idx) And idx < 15
idx += 1
End While
If (idx = 0 Or idx = 15) Then
TextBoxTemp.Text = "Out Of Range"
Else
Temperature_high = Thermistor_Temp(idx)
Temperature_low = Thermistor_Temp(idx - 1)
Resistance_low = Thermistor_R(idx)
Resistance_high = Thermistor_R(idx - 1)
Rnum1 = Resistance_high - r
Rnum2 = Resistance_high - Resistance_low
Result = 2.5 + Math.Round(Temperature_low + (5 * Rnum1 / Rnum2), 1)
TextBoxTemp.Text = Result & "C"
End If
Anyhow, you get an error trying to convert a string to an Integer. It must be becouse you try to convert a TextBox.Text property before you have initialized its value, so it has nothing to do with your CheckBox. Like you are using different timers to read and modify the values, I think you have not synchronized them correctly.
On the other hand, this is too much UI dependent. I would rather encapsulate all this stuff within a class and use just one timer to update the UI controls with the values this class returns.
|
|
|
|
|
Thanks It work already Cheer to programmer
|
|
|
|
|
hi,
i have written a code,my current code captures real time temperature,it adds the captured temperature to the database.But the problem is the code keeps running infinite.I want it to start from 0(database slot) and stop at 288 (database slot)and to keep running in a loop.How do i do it.Please advice.
Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
Dim cBuilder As New OleDb.OleDbCommandBuilder(dAdapter)
Dim dsNewRow As DataRow
dsNewRow = dSet.Tables("test1").NewRow()
dsNewRow.Item("Temperature") = TextBox8.Text
dSet.Tables("test1").Rows.Add(dsNewRow)
dAdapter.Update(dSet, "test1")
dSet.Clear()
dAdapter.Fill(dSet, "test1")
End Sub
|
|
|
|
|
so count the number of times your code snippet is running and make the timer stop when you had enough.
|
|
|
|
|
i understand by putting a timer, it will stop it from sending temperature data to the database.. but i also need it to send data up to 288 and overwrite the data from 0-288 again
|
|
|
|
|
'Dim xmlfile As Stream = My.Resources.ResourceManager.GetStream("xxxx.xml")
Dim reader As New StringReader(My.Resources.ResourceManager.GetString("xxxx.xml"))
'fills datagridview with xml information'
Dim xdoc As XmlDocument = New XmlDocument
xdoc.Load(reader.ReadToEnd())
I need some help finding a solution to the code above. I'm using an embedded resource xml file. It comes up as null every time. Are there any suggestions on what to do in this situation or should I take another route.
modified on Wednesday, November 10, 2010 8:13 PM
|
|
|
|
|
Have you read the documentation? See the parameters description here[^]. It says: "URL for the file containing the XML document to load." You are passing it the content of the file to load.
|
|
|
|
|
I have been reading but it there a way to add onto an embedded resource?
|
|
|
|
|
Not a supported one, no. Resources are read-only.
Why? Because your .EXE is locked by the system while it's running.
|
|
|
|
|
As Dave has told you, I think an embedded resource cannot be modified at runtime. However, depending on what your requirements are, Application settings[^] might be enough.
|
|
|
|
|
Its just that I'm trying to secure this file and encrypting the xml is fine but when decrypting its been one big head ache. I'm trying to secure this file but the application needs to be able to read the contents of the file.
|
|
|
|
|
So, what I understand is that you have the encrypted file as a resource on your application, don't you? Then use a CryptoStream to read it.
|
|
|
|
|
Need some advice!
In the beginnings of a new project and have to look at system security
Phase I is a hot desk based windows application
Phase II is an extranet solution to extend to remote offices
unsure of how to work this to the best advantage of dot net. Does anyone know of any good reading material or solutions that I should read upon?
Many thanks
Simon
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
I think a multitier architecture might be a good approach.
|
|
|
|
|
Im currently developing these in a multi tier methodology but
1. the desktop application has to be "hot desk" enabled
2. and a extranet
but at present both areas are seperate, but the manager would like to have the security aspect a single unit that serves both applications
Thanks
Simon
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
modified on Wednesday, November 10, 2010 5:15 PM
|
|
|
|
|
How to answer this question depends entirely on what you're trying to secure, which you haven't said anything about.
Are you taking about CD-KEY type security? Communication channels? Remoting? Database security? Storing passwords? Credit card info? ..., ..., ..., ...
|
|
|
|
|
Thanks for your reply Dave.
What I am trying to achieve is that in the desktop side of the application users need to login to the apication for use and their appropriate security levels to be given. Phase I is supposed to be built around a hot desk environment potential one user could sit at a different desk per day.
In phase II they want to introduce an extranet for the remote offices. Again when they log into the application, their security levels / restrictions are set
My boss would like to have an approach where only one set of logon information is stored regardless if they log in one day via the extranet on a client site and another day via the windows desktop application another.
Is this possible and what should I read up on? To achieve his vision?
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
Simon_Whale wrote: Does anyone know of any good reading material or solutions that I should read upon?
MSDN P&P on security[^], from 2005 - already marked outdated. The accompanying checklist is here[^]
I are Troll
|
|
|
|
|
|
This might be a touch simplistic, but isn't this exactly what a web-based deployment was designed to solve?
I'm just wondering...
|
|
|
|
|
It is the reason why many applications are web based. That and the ease of deployment/update.
|
|
|
|
|
I would agree with you, but it is something they dont want to go down, a full web based solution
As barmey as a sack of badgers
Dude, if I knew what I was doing in life, I'd be rich, retired, dating a supermodel and laughing at the rest of you from the sidelines.
|
|
|
|
|
windows XP, vb6
My vb6 project requires to reference A.dll in order to run properly. In my PC, the compiled .exe program runs normally. BUT when i deployed it to another computer, it does not run normally. UNTIL I realised i have to register the dll on that computer.
I did not realize it had to do with registering the dll because I did not register the dll on my PC before. It seems that when I compile my project, vb6 automatically registers A.dll. Therefore it ran nomally on my PC.
Therefore, I have coded my program to auto-register the A.dll itself. And I tested on my PC, it was ok. But again when I deployed to another PC, it doesn't work.
QUESTION:
Even after I unregistered the A.dll on my PC, I still can run my program normally! For some reason, vb6 keeps locking on to my dll. and I cant seem to unregister it. Therefore I am unable to test my auto-registering code!
How can I unregister the A.dll on my PC, so that I can test out the auto-registering of the A.dll itself?? I would prefer to perform the testing on my PC than to deploy it over and over again to find out if my code works.
|
|
|
|
|
It's been long from the last time I used VB6, so maybe I am wrong but, have you tried to deploy the dll file in the same location as your exe file? As far as I can remember, this way you can forget about registering the library.
|
|
|
|