Problem "Type Mismatch" in serial Script

#1

Hello everyone.

I am currently making a script to send serial strings to my arduino card when the players are playing or stopped but mairlist can’t load it.

I have " [Error] : Type mismatch" after every lines concerning the com port like

ComPort(10).SetParameters(9600, 8, ‘N’, 1);
ComPort(10).Open;
ComPort(10).SendStr(‘pfl on’);
ect …
Here is the code :

procedure OnLoad;
begin
ComPort(10).SetParameters(9600, 8, ‘N’, 1);
ComPort(10).Open;
end;
procedure OnPlayerStateChange(PlaylistIndex: integer; PlayerIndex: integer; OldState: TPlayerState; NewState: TPlayerState; Item: IPlaylistItem);
begin
if (PlayerIndex = 0) and (PlayerIndex= 0) and (NewState = psPlaying) then // Player 1 is now “playing”
ComPort(10).SendStr(‘pfl on’);
if (PlayerIndex = 0) and (PlayerIndex= 0) and (NewState = psStopped) then // Player 1 is now “stopped”
ComPort(10).SendStr(‘pfl off’);
end;
begin
end.

I also use the ComPort 10 to receive commands form the arduino card.
Thanks for your help

#2

Hi Louis,

are the quotes in the expressions the correct ones like 'N' and not typographic ones: ‘N’? Maybe this happened only while pasting into the forum, but who knows?

(Please remember while pasting to mark code as such, with the </>-Button above.)

Apart from that you refer to Playerindex = 0 twice in the same if-statement. Maybe one of them should read PlaylistIndex = 0.

And it maybe better to use else if instead of the second if (but remember: no semicolon before else!).

Pasted regards

TSD

#3

Try ComPort('COM10')instead of ComPort(10).

#4

Hello,

Thanks Tondose for all your advices The 'N' became a ‘N’ with the copy/paste, it create a syntaxe error.

The problem is solve ! I’ve replaced ComPort(10) by ComPort('COM10') and it works, thanks Torben !
Here it is :

procedure OnLoad; //Lors du chargement du script
begin
ComPort('COM6').SetParameters(9600, 8, 'N', 1);
ComPort('COM6').Open;
end;

// Playlists
procedure OnPlayerStateChange(PlaylistIndex: integer; PlayerIndex: integer; OldState: TPlayerState; NewState: TPlayerState; Item: IPlaylistItem); //Lors du changement de statut des lecteurs
begin

// Player 1-1 Playing
if (PlaylistIndex = 0) and (PlayerIndex= 0) and (NewState = psPlaying) then
ComPort('COM6').SendStr('pfl on')

// Player 1-1 Stopped
else if (PlaylistIndex = 0) and (PlayerIndex= 0) and (NewState = psStopped) then
ComPort('COM6').SendStr('pfl off');

// Player 1-2 Playing
if (PlaylistIndex = 0) and (PlayerIndex= 1) and (NewState = psPlaying) then
ComPort('COM6').SendStr('pfl on')

// Player 1-2 Stopped
else if (PlaylistIndex = 0) and (PlayerIndex= 1) and (NewState = psStopped) then
ComPort('COM6').SendStr('pfl off');

end;

begin
end.

Best regards
(Sorry for the layout of my previous post, i’m a newbie on the forum)