VERSION 5.00 Object = "{648A5603-2C6E-101B-82B6-000000000014}#1.1#0"; "MSCOMM32.OCX" Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX" Begin VB.Form FormCTRL BackColor = &H80000000& Caption = "StartPos V0" ClientHeight = 6495 ClientLeft = 60 ClientTop = 450 ClientWidth = 11880 FillColor = &H80000000& FillStyle = 0 'Solid BeginProperty Font Name = "Courier New" Size = 48 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty FontTransparent = 0 'False ForeColor = &H80000008& LinkTopic = "Form1" ScaleHeight = 6074.148 ScaleMode = 0 'User ScaleWidth = 10274.59 Begin VB.TextBox RS232IN CausesValidation= 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 600 TabIndex = 24 Text = "RS232IN" Top = 5160 Width = 10695 End Begin VB.TextBox PosIni Alignment = 1 'Right Justify CausesValidation= 0 'False BeginProperty Font Name = "Courier New" Size = 36 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 870 Left = 720 TabIndex = 23 Text = "PosIni" Top = 1560 Width = 1575 End Begin VB.TextBox V6 CausesValidation= 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 10440 TabIndex = 16 Text = "VBEMF6" Top = 1920 Width = 855 End Begin VB.TextBox V3 CausesValidation= 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 6120 TabIndex = 15 Text = "VBEMF3" Top = 1920 Width = 855 End Begin VB.TextBox V5 CausesValidation= 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 9000 TabIndex = 14 Text = "VBEMF5" Top = 1920 Width = 855 End Begin VB.TextBox V2 CausesValidation= 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 4680 TabIndex = 13 Text = "VBEMF2" Top = 1920 Width = 855 End Begin VB.TextBox V4 CausesValidation= 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 7560 TabIndex = 12 Text = "VBEMF4" Top = 1920 Width = 855 End Begin VB.TextBox V1 CausesValidation= 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 12 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 3240 TabIndex = 11 Text = "VBEMF1" Top = 1920 Width = 855 End Begin VB.TextBox V5V CausesValidation= 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 4200 TabIndex = 9 Text = "V 5V" Top = 240 Width = 855 End Begin MSComctlLib.ImageList ImageList1 Left = 9480 Top = 600 _ExtentX = 1005 _ExtentY = 1005 BackColor = -2147483643 ImageWidth = 32 ImageHeight = 32 MaskColor = 12632256 _Version = 393216 BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} NumListImages = 3 BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} Picture = "Scroll.frx":0000 Key = "Red" Object.Tag = "Red" EndProperty BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} Picture = "Scroll.frx":0452 Key = "Green" Object.Tag = "Green" EndProperty BeginProperty ListImage3 {2C247F27-8591-11D1-B16A-00C0F0283628} Picture = "Scroll.frx":08A4 Key = "Yellow" Object.Tag = "Yellow" EndProperty EndProperty End Begin VB.PictureBox PictureCOM AutoSize = -1 'True BorderStyle = 0 'None CausesValidation= 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 480 Left = 9000 Picture = "Scroll.frx":0CF6 ScaleHeight = 480 ScaleWidth = 480 TabIndex = 8 TabStop = 0 'False Top = 3600 Width = 480 End Begin VB.Timer Timer2 Left = 10320 Top = 720 End Begin VB.Timer Timer1 Left = 8520 Top = 600 End Begin VB.TextBox Text7 Appearance = 0 'Flat CausesValidation= 0 'False Enabled = 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 360 Left = 3120 TabIndex = 0 TabStop = 0 'False Text = "Text7" Top = 4560 Width = 5775 End Begin VB.TextBox IMotor CausesValidation= 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 960 TabIndex = 5 Text = "IMotor" Top = 840 Width = 855 End Begin VB.TextBox VBat CausesValidation= 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 960 TabIndex = 4 Text = "VBat" Top = 240 Width = 855 End Begin VB.CommandButton CloseCOM Caption = "Close COM" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 7320 TabIndex = 3 Top = 3600 Width = 1215 End Begin VB.TextBox Text3 Appearance = 0 'Flat CausesValidation= 0 'False Enabled = 0 'False BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty ForeColor = &H80000007& Height = 360 Left = 3120 TabIndex = 1 TabStop = 0 'False Text = "Text3" Top = 4200 Width = 5775 End Begin MSCommLib.MSComm MSComm1 Left = 7320 Top = 360 _ExtentX = 1005 _ExtentY = 1005 _Version = 393216 DTREnable = -1 'True End Begin VB.CommandButton OpenCOM Caption = "Open COM" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 495 Left = 5760 TabIndex = 2 Top = 3600 Width = 1215 End Begin VB.Label Label2 Caption = "bldc.wikidot.com" BeginProperty Font Name = "Courier New" Size = 11.25 Charset = 0 Weight = 700 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 5040 TabIndex = 25 Top = 5760 Width = 2295 End Begin VB.Label Label22 Caption = "6" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 10080 TabIndex = 22 Top = 2040 Width = 135 End Begin VB.Label Label21 Caption = "3" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 5760 TabIndex = 21 Top = 2040 Width = 135 End Begin VB.Label Label20 Caption = "5" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 8640 TabIndex = 20 Top = 2040 Width = 135 End Begin VB.Label Label5 Caption = "2" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 4320 TabIndex = 19 Top = 2040 Width = 135 End Begin VB.Label Label4 Caption = "4" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 7200 TabIndex = 18 Top = 2040 Width = 135 End Begin VB.Label Label3 Caption = "1" BeginProperty Font Name = "MS Sans Serif" Size = 8.25 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 255 Left = 2880 TabIndex = 17 Top = 2040 Width = 135 End Begin VB.Label Label1 Alignment = 1 'Right Justify Caption = "V 5V" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 3480 TabIndex = 10 Top = 360 Width = 615 End Begin VB.Label Label9 Alignment = 1 'Right Justify Caption = "I Motor" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 240 TabIndex = 7 Top = 960 Width = 615 End Begin VB.Label Label8 Alignment = 1 'Right Justify Caption = "VCC" BeginProperty Font Name = "MS Sans Serif" Size = 9.75 Charset = 0 Weight = 400 Underline = 0 'False Italic = 0 'False Strikethrough = 0 'False EndProperty Height = 375 Left = 240 TabIndex = 6 Top = 360 Width = 615 End End Attribute VB_Name = "FormCTRL" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = True Attribute VB_Exposed = False Option Explicit Dim RPM_MAX As Integer Dim PWM_MAX As Integer Dim ByteIN As Single 'String Dim ByteOUT As Byte Dim ByteAnt1 As Single Dim ByteAnt2 As Single Dim ByteAnt3 As Single Dim ComOK As Boolean Dim CommandInd As Single Dim Command As Single Dim Command_lenght As Single Dim ADC_BG As Integer Dim TX_Flag As Boolean Private Sub Form_Load() RPM_MAX = 20000 'Definir RPM Max no CTRL PWM_MAX = 100 'Definir PWM Max no CTRL e ComOK = False 'o motor pode ultrapassar RPM ... Command_lenght = 0 FormCTRL.RS232IN = "" FormCTRL.Text3 = "" FormCTRL.Text7 = "" Set FormCTRL.PictureCOM.Picture = FormCTRL.ImageList1.ListImages("Red").Picture 'set formctrl.RS232IN. End Sub Private Sub OpenCOM_Click() ' Buffer to hold input string Dim Instring As String ' Use COM1. If MSComm1.PortOpen = False Then FormCTRL.Text3 = "Vai abrir COM ..." MSComm1.CommPort = 1 ' 2400 baud, no parity, 8 data, and 1 stop bit. MSComm1.Settings = "38400,N,8,1" ' Tell the control to read entire buffer when Input ' is used if 0. MSComm1.InputLen = 1 'Setting RThreshold to 1, for example, causes the MSComm control 'to generate OnComm event every time a single character is placed receive buffer MSComm1.RThreshold = 1 ' Open the port. MSComm1.PortOpen = True ' Send the attention command to the modem. MSComm1.Output = "OK" + vbCrLf ' Wait for data to come back to the serial port. ' Do ' DoEvents ' Buffer$ = Buffer$ & MSComm1.Input ' Loop Until InStr(Buffer$, "OK" & vbCrLf) ' ' Read the "OK" response data in the serial port. ' ' Close the serial port. ' MSComm1.PortOpen = False Set FormCTRL.PictureCOM.Picture = FormCTRL.ImageList1.ListImages("Yellow").Picture ' This procedure sets the InputLen property, which determines how ' many bytes of data are read each time Input is used ' to retreive data from the input buffer. ' Setting InputLen to 0 specifies that ' the entire contents of the buffer should be read. ' MSComm1.InputLen = 0 ' This procedure sets the RThreshold property, which determines ' how many bytes can arrive at the receive buffer before the OnComm ' event is triggered and the CommEvent property is set to comEvReceive. ' MSComm1.RThreshold = 1 Else: FormCTRL.Text3 = "COM já aberta..." FormCTRL.Text7 = MSComm1.Input End If End Sub Private Sub CloseCOM_Click() If MSComm1.PortOpen = True Then FormCTRL.Text3 = "Vai fechar COM ..." MSComm1.PortOpen = False Set FormCTRL.PictureCOM.Picture = FormCTRL.ImageList1.ListImages("Red").Picture ComOK = False Else: FormCTRL.Text3 = "COM já fechada ..." End If End Sub Private Sub MSComm1_OnComm() Select Case MSComm1.CommEvent ' Handle each event or error by placing ' code below each case statement ' Errors ' Events Case comEvCD ' Change in the CD line. FormCTRL.Text3 = "EvCD" Case comEvCTS ' Change in the CTS line. FormCTRL.Text3 = "EvCTS" Case comEvDSR ' Change in the DSR line. FormCTRL.Text3 = "EvDSR" Case comEvRing ' Change in the Ring Indicator. FormCTRL.Text3 = "EvRing" Case comEvReceive ' Received RThreshold # of ' chars. FormCTRL.Text3 = "EvReceive" ByteIN = Asc(MSComm1.Input) FormCTRL.RS232IN = Right(FormCTRL.RS232IN, 120) + Chr(ByteIN) 'If ComOK = True Then FormCTRL.Text7 = Right(FormCTRL.Text7, 65) + Str(ByteIN) 'End If ByteAnt3 = ByteAnt2 ByteAnt2 = ByteAnt1 ByteAnt1 = ByteIN If ComOK = False Then If Right(FormCTRL.RS232IN, 3) = "OK!" Then Set FormCTRL.PictureCOM.Picture = FormCTRL.ImageList1.ListImages("Green").Picture ComOK = True CommandInd = 0 End If Else 'ComOK=True If Right(FormCTRL.RS232IN, 3) = "OK!" Then CommandInd = 0 Else CommandInd = CommandInd + 1 If CommandInd = 1 Then Command = ByteIN Select Case Command Case 2 To 5, 10, 33 To 38, 39 Command_lenght = 2 Case 17 Command_lenght = 3 Case Else ComOK = False Set FormCTRL.PictureCOM.Picture = FormCTRL.ImageList1.ListImages("Yellow").Picture End Select End If If CommandInd = Command_lenght Then CommandInd = 0 FormCTRL.Text7 = Right(FormCTRL.Text7, 65) + "|" Select Case Command 'Case 1 ' ADC_BG = ByteAnt2 * 256 + ByteAnt1 ' FormCTRL.V5V = Round(1024 * 1.24 / ADC_BG, 3) '1.23 Case 2 FormCTRL.VBat = Round(4 * (227 / 47) * ByteAnt1 * 1.15 / ADC_BG, 3) '1.23 Case 3 ' , 255 FormCTRL.IMotor = Round(ByteAnt1, 3) FormCTRL.IMotor.BackColor = &H80000005 Case 10 FormCTRL.IMotor = Round(ByteAnt1, 3) FormCTRL.IMotor.BackColor = &HFF Case 17 ADC_BG = ByteAnt2 * 256 + ByteAnt1 FormCTRL.V5V = Round(1024 * 1.15 / ADC_BG, 3) '1.23 Case 33 ' V1 FormCTRL.V1 = Round(ByteAnt1, 3) Case 34 ' V2 FormCTRL.V2 = Round(ByteAnt1, 3) Case 35 ' V3 FormCTRL.V3 = Round(ByteAnt1, 3) Case 36 ' V4 FormCTRL.V4 = Round(ByteAnt1, 3) Case 37 ' V5 FormCTRL.V5 = Round(ByteAnt1, 3) Case 38 ' V6 FormCTRL.V6 = Round(ByteAnt1, 3) Case 39 ' PosIni FormCTRL.PosIni = Round(ByteAnt1, 3) * 10 End Select End If End If End If Case comEvSend ' There are SThreshold number of ' characters in the transmit ' buffer. FormCTRL.Text3 = "EvSend" Case comEvEOF ' An EOF charater was found in ' the input stream FormCTRL.Text3 = "EvEOF" End Select End Sub