

			USO DELLA LIBRERIA SFBP232.DLL IN VISUAL BASIC
			==============================================
			Febbraio 2009


			MIT License with Attribution
			----------------------------

			Copyright (c) 2004-2025 Claudio H. G.

			Permission is hereby granted, free of charge, to any person obtaining a copy
			of this software and associated documentation files (the "Software"), to deal
			in the Software without restriction, including without limitation the rights
			to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
			copies of the Software, subject to the following conditions:

			- The above copyright notice and this permission notice shall be included
			  in all copies or substantial portions of the Software.

			- The origin of this Software must not be misrepresented. If used in a product,
			  an acknowledgment is appreciated (e.g., Uses the SFBP Protocol Library by Claudio H.G.).

			- If a product uses the Software, it is recommended that the SFBP logo be displayed 
			  in a visible location. The logo is provided free of charge and available for use 
			  under the same license terms.			  

			THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, 
			INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR 
			PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE 
			FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 
			OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
			DEALINGS IN THE SOFTWARE.

**********************************************************************************************************

Per utilizzare la libreria SFBP232 che consente di accedere ad un porto di comunicazione seriale COM 232,
anche attraverso eventuali adattatori USB,  necessario inserire nel progetto in visual basic dei seguenti
files:

NSCCOMhelper.bas		che fornisce le funzioni di base e i prototipi per il collegamento
				alla libreria dinamica

frmSFBP232Settings.frm		form per le impostazioni di configurazione
frmSFBP232Settings.frx




INsccom.cls			Opzionale. Classe da usare come template se si desidera sfruttare un oggetto 
				invece di inserire le procedure-evento chiamate in callback dalla libreria in
				una form standard

				ATTENZIONE! Nel caso si desideri usare questo file, effettuare le
				implementazioni previste nelle varie procedure, quindi salvarlo in modo
				privato nella propria applicazione, lasciando inalterato il template originale.
				Inoltre occorre impostare la seguente variabile di compilazione nel progetto:
					NSCCOMHLPR_USE_CLASS = 1

				Se si desidera usare una normale form, non caricare questo file di classe.




Inserimento in una form standard.
=================================

Se si desidera, in luogo in oggetto costruito sulla classe template, usare una form standard, copiare le
seguenti procedure e incollarle nella form da usare. Notare che in questo caso non si deve inserire alcuna
variabile di compilazione.


copiare e incollare nella form:
-----------------------------------------------------------------------------------------------------
Public Sub Nsccom1_COMerror()
End Sub

Public Sub Nsccom1_DataReady(srcAddress As Integer, destAddress As Integer, datalen As Integer, msgType As Integer, pBuf As Long, pckType As enumPacketType, buf() As Byte)
End Sub

Public Sub Nsccom1_FirmwareInfo(Address As Integer, Serial As String, devID As Integer, Device As String, MinorVersion As Integer, MajorVersion As Integer, Version As String)
End Sub

Public Sub Nsccom1_Map(Address As Integer, Serial As String, devID As Integer, MinorVersion As Integer, MajorVersion As Integer)
End Sub

Public Sub Nsccom1_MapProgress(level As Integer)
End Sub

Public Sub Nsccom1_NetError(ErrCode As Integer, ErrMsg As String)
End Sub

Public Sub Nsccom1_ProgramCompleted()
End Sub

Public Sub Nsccom1_ProgramProgress(level As Integer, status As String)
End Sub

Public Sub Nsccom1_QueryReply(Address As Integer, lpData As Long, queryID As Integer)
End Sub

Public Sub Nsccom1_RemoteError(Address As Integer, ErrorCode As Integer, ErrorString As String)
End Sub
-----------------------------------------------------------------------------------------------------


Quindi popolare ogni procedura nel modo desiderato, o lasciarla vuota.



Per avviare l'uso della libreria  necessario invocare la funzione setUpNSCCOMLIB passanto la form in cui
sono state inserite le procedure, che sar anche quella usata per il subclass per la gestione dei messaggi
di evento della seriale.
(Nota. Se si usa un oggetto costruito con la classe, invece che incollare le funzioni in una propria form,
con la creazione dell'oggetto viene inizializzata la libreria, e non occorre invocare setUpNSCCOMLIB).

Quando si  terminato l'uso della libreria occorre invocare la funzione cleanNSCCOMLIB che provvede a
rimuovere il riferimento all'oggetto (derivato dalla classe, o form).



In una form, tipicamente si inserisce in Form_Load e Form_Unload:

Private Sub Form_Load()
setUpNSCCOMLIB Me	' Setup callback functions (Nsccom1_...) and bind this window to the helper module
End Sub

Private Sub Form_Unload(Cancel As Integer)
Me.CloseCOM
cleanNSCCOMLIB		' Unbind the window to the helper module
End Sub

Nella stessa form aggiungere le funzioni:

Public Function OpenCOM() As Boolean
' Helper module calls the DLL OpenCOM giving the bound window to start subclassing
OpenCOM = CBool(NSCCOMhelper.OpenCOM() = 1)
If NSCCOMhelper.IsOpen = 1 Then
  ' OK open
Else
  ' Failed
End If
End Function

Public Sub CloseCOM()
NSCCOMhelper.closeCOM
NSCCOMhelper.SetClientHWND 0	' This releases window subclassing
End Sub




Public mApplicationPort As Integer
Public mDefaultPort As Integer

Sono due variabili pubbliche che corrispondono ai valori del porto specifico dell'applicazione (che non
viene salvato nei valori di default, e occorre salvare in privato nel caso si voglia richiamare)
e il porto che era di default se  stato impostato il valore specifico per applicazione (ad uso privato).
Per impostare il porto di applicazione per via programmatica usare la funzione SetApplicationPort.

Impostando il porto per l'applicazione, pi canali di comunicazione possono operare simultaneamente su
diversi porti.
E' anche possibile, prima di aprire la comunicazione, impostare l'indirizzo di stazione, che non sar
memorizzato nei valori di default fino a quando non si invochi SaveSFBPdriverSettings (attenzione che
questo pu essere realizzato dall'utente se si apre la form di impostazioni!)



Form di impostazioni
====================

Per aprire la form di impostazioni semplicemente creare e aprire frmSFBP232Settings (tipicamente in modale).
Esempio:

Private Sub cmdSettings_Click()
frmSFBP232Settings.Show 1
End Sub

